1

I am using http-proxy to proxy my requests. I am using https not http. The first request is a login request and works fine. The second request is to connect to socket.io which doesn't works even doesn't show any error. I have backend server which listens at port 3000 and handles both requests. Where is something wrong with in my code? The socket.io connection doesn't get established, even no error or anything is printed in the console to know root cause of the problem. I think it doesn't even gets upgraded. What do I do to make it work?

var app = require('express')();
const https = require('https');
const fs = require('fs');
var httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer({ws:true});
var server=https.createServer(credentials, app).listen(8082)

app.use('/login', function (req, res) {
   console.log("Request Url "+req.url)
   proxy.web(req, res,{target:'example.com:3000'})
})

app.use('/socket.io',function(req,socket,head){
    console.log("Request Url "+req.url)
    server.on('upgrade', function(req, socket, head) {
        socket.on('error', (error) => {
             console.error(error);
         });
        proxy.ws(req, socket, head, {target:'example.com:3000'})
      });
})

What I have tried ws:true, secure:true options while proxying requests. Error eventlistener doesn't print any errors. Any help would be appreciated.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.