Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new vue.js project preview yields "Invalid Host header" #26

Closed
csells opened this issue Aug 28, 2018 · 20 comments
Closed

new vue.js project preview yields "Invalid Host header" #26

csells opened this issue Aug 28, 2018 · 20 comments

Comments

@csells
Copy link

csells commented Aug 28, 2018

Installing the vue cli via "npm i -g @vue/cli" and running "vue create hello-world" worked great. However, running it with "yarn serve" and previewing the output on port 8080 yielded a page that said only "Invalid Host header".

@svenefftinge
Copy link
Member

The dev server isn't accepting external requests. You need to put below's config

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

@csells
Copy link
Author

csells commented Aug 28, 2018

Yep. That did the trick.

@csells csells closed this as completed Aug 28, 2018
@svenefftinge
Copy link
Member

Also the host needs to be passed and set to 0.0.0.0 as it defaults to only accepting localhost.

webpack-dev-server --host 0.0.0.0

@svenefftinge
Copy link
Member

Btw. the latest update includes full support for *.vue files.

@Code9117
Copy link

Thanks!your answer.my name is bobo.

@tribals
Copy link

tribals commented Dec 27, 2018

Closed, but it is better to use devServer.public: https://webpack.js.org/configuration/dev-server/#devserver-public

@sobiero
Copy link

sobiero commented Jul 10, 2019

The dev server isn't accepting external requests. You need to put below's config

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

Where is the file vue.config.js located or do I need to create it? I'm using vue/cli 3.9

dilawar pushed a commit to dilawar/HippoApp that referenced this issue Jul 22, 2019
Till upstream is fixed there is not escape.
@brunogcpinheiro
Copy link

@sobiero Yes, create it in root!

@scozma
Copy link

scozma commented Nov 14, 2019

The dev server isn't accepting external requests. You need to put below's config

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

Where is the file vue.config.js located or do I need to create it? I'm using vue/cli 3.9

You can create a file with that name if you don't have it and add it on the root of your project (same level as package.json for example)

@qkmc-rk
Copy link

qkmc-rk commented Mar 3, 2020

The dev server isn't accepting external requests. You need to put below's config

// vue.config.js
module.exports = {
// options...
devServer: {
disableHostCheck: true
}
}
Where is the file vue.config.js located or do I need to create it? I'm using vue/cli 3.9
You can create a file with that name if you don't have it and add it on the root of your project (same level as package.json for example)

bonyii pushed a commit to bonyii/udemy_microservices that referenced this issue Aug 10, 2020
bonyii pushed a commit to bonyii/udemy_microservices that referenced this issue Aug 10, 2020
@jp96201
Copy link

jp96201 commented Sep 1, 2020

ssfa

@mittalyashu
Copy link

mittalyashu commented Oct 17, 2020

@svenefftinge

I tried passing the url with --public flag but it didn't work either

yarn run dev --public $GITPOD_WORKSPACE_URL

Even tried passing the port

--public $GITPOD_WORKSPACE_URL:443

Also, using disableHostCheck: true doesn't to pose security risk?

@jannikbuscha
Copy link

this fixed the error for me:
devServer: { allowedHosts: 'all', },

@Teeratach-Thawilwang
Copy link

Teeratach-Thawilwang commented Mar 23, 2022

this fixed the error for me: devServer: { allowedHosts: 'all', },

This answer helps me a lot. Thank!
for vue-cli-service version ~5.0.0 and my vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: { allowedHosts: 'all', },
  pluginOptions: {
    moment: {
      locales: [
        ''
      ]
    }
  }
})

@zhangshoucheng1
Copy link

开发服务器不接受外部请求。您需要在下面放置配置

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

great

@ranji31
Copy link

ranji31 commented Jul 22, 2023

is same as for ionic angular? I'm include above the module file but is still showing "Invalid Host Header"

@SheikhElMoctarG
Copy link

is same as for ionic angular? I'm include above the module file but is still showing "Invalid Host Header"

I'm too

@SheikhElMoctarG
Copy link

I fixed it, only change your vue.config.js:
module.exports = defineConfig({ transpileDependencies: true, devServer: { allowedHosts: 'all', client: {webSocketURL: 'auto://0.0.0.0:0/ws'}}, })

@madlife12327
Copy link

madlife12327 commented Jan 1, 2024

I fixed it, only change your vue.config.js: module.exports = defineConfig({ transpileDependencies: true, devServer: { allowedHosts: 'all', client: {webSocketURL: 'auto://0.0.0.0:0/ws'}}, })

right,if you use vue-cli greater than version 5 ,please change vue.config.js to devServer:{allowedHosts:'all'} ,
otherwise use less than vue-cli version 5, change vue.config.js to devServer:{disableHostCheck: true}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests