-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
The webpack-dev-server does not explicitly handle websockets through the proxy option. I would expect an entry like this to correctly proxy websocket requests:
proxy : [{path: /ws, target: ws://localhost:8080/, ws: true}]
After inspecting the Server.js file, it seem that there would need to be explicit handling of websockets. Something like this perhaps:
options.proxy.forEach(function (proxyOptions) {
app.all(proxyOptions.path, function (req, res) {
if(typeof proxyOptions.rewrite === 'function') proxyOptions.rewrite(req, proxyOptions);
if (proxyOptions.host) {
req.headers.host = proxyOptions.host;
}
if (proxyOptions.ws) {
proxy.ws(req, res, proxyOptions, errorCb.bind(this));
} else {
proxy.web(req, res, proxyOptions, errorCb.bind(this));
}
function errorCb(err){
var msg = "cannot proxy to " + proxyOptions.target + " (" + err.message + ")";
this.io.sockets.emit("proxy-error", [msg]);
res.statusCode = 502;
res.end();
}
if (proxyOptions.configure) {
proxyOptions.configure(proxy);
}
}.bind(this));
}.bind(this));
or add a new listener for websocket connections:
proxyServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head);
});
tss0823 and levitation
Metadata
Metadata
Assignees
Labels
No labels