美文网首页
nodejs/webpack项目提示Invalid Host h

nodejs/webpack项目提示Invalid Host h

作者: YHWXQ简简单单的生活 | 来源:发表于2017-08-28 09:35 被阅读1022次

    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/');
      });
    });
    

    相关文章

      网友评论

          本文标题:nodejs/webpack项目提示Invalid Host h

          本文链接:https://www.haomeiwen.com/subject/joewdxtx.html