1. 程式人生 > >內網穿透 vue 返回 invalid host header

內網穿透 vue 返回 invalid host header

問題:使用花生殼內網穿透只返回304,invalid host header

原因:新版的webpack-dev-server出於安全考慮,預設檢查hostname,如果hostname不是配置內的,將中斷訪問。

解決:webpack.dev.conf.js新增配置 disableHostCheck: true,

  devServer: {
    clientLogLevel: 'warning',
    historyApiFallback: {
      rewrites: [
        { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
      ],
    },
    hot: true,
    contentBase: false, // since we use CopyWebpackPlugin.
    compress: true,
    host: HOST || config.dev.host,
    port: PORT || config.dev.port,
    open: config.dev.autoOpenBrowser,
    overlay: config.dev.errorOverlay
      ? { warnings: false, errors: true }
      : false,
    publicPath: config.dev.assetsPublicPath,
    proxy: config.dev.proxyTable,
    quiet: true, // necessary for FriendlyErrorsPlugin
    watchOptions: {
      poll: config.dev.poll,
    },
	disableHostCheck: true,
},