Closed hossein-zare closed 2 years ago
@hossein-zare I am getting the same issue. Do you know how to fix this?
@VladislavMurashchenko
I used http-proxy:
const require('http-proxy');
const app = express();
const server = http.createServer(app);
const proxy = httpProxy.createProxyServer({
target: {
host: 'example.com',
port: 4001
}
});
server.on('upgrade', (req, socket, head) => {
const domain = req.headers.host;
const host = domain.split(':')[0];
if (host === 'socket.example.com') {
proxy.ws(req, socket, head);
} else {
socket.destroy();
}
});
Can you try with v2.0.6
?
It contains a fix for server crashes from websocket errors
Think the filter option is what you were looking for:
// only proxy on this condition:
const filter = (path, req) => {
const domain = req.headers.host;
const host = domain.split(':')[0];
return host === 'socket.example.com'
}
const conf = {
target: `http://mydomain.com:4000`,
changeOrigin: true,
ws: true,
router: {
'socket.mydomain.com:4000': `http://mydomain.com:4001`,
}
};
const wsProxy = createProxyMiddleware(filter, conf);
still broken
@chimurai node-http-proxy socket will throw error if no error listener for default eventemitter
how to: just
this.proxy.ws(req, socket, head, activeProxyOptions, this.logError);
Checks
http-proxy-middleware
.Describe the bug (be clear and concise)
I want to proxy
socket.mydomain.com:4000
to a websocket server running atmydomain.com:4001
.it's working fine but If i change
socket.domain.com
toapp.domain.com
the server tries to upgrade to websocket then craches.Log
Step-by-step reproduction instructions
Expected behavior (be clear and concise)
The server must not crash if the client tries to connect to another subdomain.
How is http-proxy-middleware used in your project?
What http-proxy-middleware configuration are you using?
What OS/version and node/version are you seeing the problem?
Additional context (optional)
No response