nodejs项目在本地访问正常,然而运行到手机上就提示Invalid Host header。
新版的webpack-dev-server出于安全考虑,默认检查hostname,如果hostname不是配置内的,将中断访问。
解决方法:
disableHostCheck: true
例如:
gulpfile.js文件中
var gulp = require("gulp");
var eslint = require('gulp-eslint');
var webpack = require("webpack");
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack/webpack.config.js');
gulp.task('server', function() {
new WebpackDevServer(webpack(config), {
noInfo: true,
publicPath: config.output.publicPath,
disableHostCheck: true, // webpack-dev-server版本是1.16.5时需要添加这个字段
hot: true,
historyApiFallback: true
}).listen(3000, '0.0.0.0', function (err, result) {
if (err) {
return console.log(err);
}
console.log('Listening at http://localhost:3000/');
});
});