Is websocket proxying working?
Author: bushevCreated Feb 5, 2022Updated Apr 2, 2025
I'm trying to run a basic example but getting an error:
TypeError: socket.setNoDelay is not a function
at Object.common.setupSocket (/home/ubuntu/http-proxy/build/webpack:/proxy-app/node_modules/http-proxy/lib/http-proxy/common.js:127:1)The code:
const proxy = httpProxy.createProxyServer({
ws: true
});
proxy.on('upgrade', (req, socket, head) => {
const { query } = Url.parse(req.url, true);
const redirectParams = { target: { host: query.csHost as string, port: parseInt(query.csPort as string, 10) } };
console.log('[WS] Redirecting (upgrade)...', { url: req.url, redirectParams });
proxy.ws(req, socket, head, redirectParams);
});
const server = http.createServer(async (req, res) => {
const { query } = Url.parse(req.url, true);
const redirectParams = { target: { host: query.csHost as string, port: parseInt(query.csPort as string, 10) } };
console.log('[HTTP] Redirecting...', { url: req.url, redirectParams });
proxy.ws(req, res, redirectParams);
}
server.listen(80);Source: http-party/node-http-proxy