Vue invalid host header
Asked Answered
F

5

11

Don't know why 2 days ago my projects ( created via vue create ) stopped working - in Chrome i get

Invalid Host Header

and

WDS Disconnected

errors. In cmd everything compiles properly( npm run serve ) I don't know webpack, so i have no idea how to fix it.

What i've already done:

  • reinstalled node
  • deleted and reinstalled all npm packages
Fourway answered 23/12, 2018 at 20:4 Comment(0)
A
10

This issue is caused by this webpack-dev-server issue that has been fixed recently.

To avoid getting the Invalid Host/Origin header error add this to your devServer entry on vue.config.js file:

disableHostCheck: true

Amendatory answered 25/12, 2018 at 12:19 Comment(0)
D
5

Note that disableHostCheck: true is not recommended because it creates security vulnerabilities.

For a dev server running on my local machine, I could resolve the issue by explicitly setting --host in vue-cli-service serve:

scripts: {
  serve: "vue-cli-service serve --host myapp.localhost"
}

The --host option is documented here.

Visit the app in your browser under myapp.localhost:8080 (assuming you're using default port 8080).

Deannedeans answered 13/3, 2021 at 8:4 Comment(1)
disableHostCheck: true didn't work for me, but this did. Thanks a ton!Skyjack
L
4

Found this question searching for the same "Invalid Host Header" issue. Here's how I solved it.

I am running Vue dev server npm run serve in Docker on my remote server. Couldn't access it at http://example.com:8080 with the error message above.

Correct and secure way is to add the domain name to the vue.config.js file:

"devServer": {
  "public": "example.com"
}

This is a fresh vue project initiated with Vue Cli command: vue create myproject with Vuetify added via vue add vuetify. Full content of my vue.config.js after that is:

module.exports = {
  "transpileDependencies": [
    "vuetify"
  ],
  "devServer": {
    "public": "example.com"
  }
}
Liverwort answered 15/2, 2020 at 6:47 Comment(0)
F
4

This is because of the dev server which isn't accepting external requests. To solve this, we've to configure vue.config.js as below.

If vue.config.js is not found in your vue project, please create the file in root directory and add the following line.

module.exports = {
    // options...
    devServer: {
        disableHostCheck: true
    }
}

Source

Foulup answered 11/1, 2022 at 6:14 Comment(1)
This was changed (probably in Vue 2->3?), you now have to do { devServer.allowedHosts: 'all' } instead. webpack.js.org/configuration/dev-server/#devserverallowedhostsSir
C
0

You can use allowedHosts: 'all' to the vue.config.js

module.exports = {
  devServer: {
    allowedHosts: 'all',
  }
}

https://webpack.js.org/configuration/dev-server/#devserverallowedhosts

Ceremony answered 24/7 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.