项目运行时页面提示Invalid Host header解决方案
现象:
1.项目运行时页面提示Invalid Host header
2.localhost能直接访问,配置host代理后提示Invalid Host header
原因:
由于webpack-dev-server升级后,为了host安全,启动的项目配置host会被禁用,需要设置disableHostCheck=true
.
设置disableHostCheck=true有二个途径。
1.在packjson.json的script中进行添加
例:
"scripts": {
"start": "webpack-dev-server --disableHostCheck=true --config ./web/webpack.config.dev.js"
}
2.在配置文件中的devServer中进行配置disableHostCheck:true
//在webpack.config.dev.js 的devServer中添加 disableHostCheck:true
devServer: {
disableHostCheck:true
}
如项目中没有webpack.config.dev,可在webpack配置文件中添加
devServer: {
disableHostCheck:true
}