項(xiàng)目運(yùn)行時(shí)頁面提示Invalid Host header解決方案
現(xiàn)象:
1.項(xiàng)目運(yùn)行時(shí)頁面提示Invalid Host header
2.localhost能直接訪問,配置host代理后提示Invalid Host header
原因:
由于webpack-dev-server升級(jí)后,為了host安全炎疆,啟動(dòng)的項(xiàng)目配置host會(huì)被禁用般哼,需要設(shè)置disableHostCheck=true
.
設(shè)置disableHostCheck=true有二個(gè)途徑岂贩。
1.在packjson.json的script中進(jìn)行添加
例:
"scripts": {
"start": "webpack-dev-server --disableHostCheck=true --config ./web/webpack.config.dev.js"
}
2.在配置文件中的devServer中進(jìn)行配置disableHostCheck:true
//在webpack.config.dev.js 的devServer中添加 disableHostCheck:true
devServer: {
disableHostCheck:true
}
如項(xiàng)目中沒有webpack.config.dev弧轧,可在webpack配置文件中添加
devServer: {
disableHostCheck:true
}