我们有多个从 webpack-dev-server 提供的索引文件:
index.html = http://eventapp.localhost
site.html = http://eventsite.localhost
forms.html = http://regsites.localhost
我们在这些前面有一个 nginx 代理来服务器 https 和 http。当 webpack 客户端连接到它时,sockjs-node
它似乎添加了端口并直接进入webpack-dev-server
而不是通过我们的 nginx 代理。这使得 HMR 在您通过 SSL 时不起作用,因为我们不使用 https 启动服务器。
有没有办法告诉它在进行 sockjs 协商时不要附加端口,让它继续使用 nginx 代理?
这是我们配置服务器的方式:
devServer: {
host: '0.0.0.0',
/// Enable gzip
compress: true,
contentBase: './dist',
/* Theoretically, the public option is better but they only support a single host
*
* This is a security issue not using public.
* */
disableHostCheck: true,
// Do not enable HMR on the server, it is enabled with --hot
// hot: true,
before: (app) => {
/* Serve the dev settings that are normally injected via nginx */
app.get('/settings.js', function (req, res) {
const fullPath = path.join(__dirname, settingsFile);
res.sendFile(fullPath);
});
app.use(historyFallback({verbose: false}));
},
},
这就是我们启动它的方式:
webpack-dev-server --hot-only --hot --env.BUILD_VERSION=development
我们正在使用此客户端,react-dev-utils/webpackHotDevClient
但它似乎尝试在没有端口的情况下进行连接,然后发生升级协商并尝试与端口连接。
我们不能使用public
和publicPath
配置选项,因为我们有多个索引。我们只需要发现连接的位置,仅使用window.location
而不添加端口等额外信息。