I use the following code and it works
          proxy.web(req, res, {
                changeOrigin: true,
                target: 'http://' + hostname + ':' + port,
                ws: true
            });
But when I try the following I got error,why?
proxy.web(req, res, {
                target: {
                    host: 'http://' + hostname,
                    port: port
                },
        });
                Because httpProxy.createProxyServer uses url.parse, which will take string as argument you can see the documentatin here https://nodejs.org/docs/latest/api/url.html
you can see the proxy server code here https://github.com/nodejitsu/node-http-proxy/blob/master/lib/http-proxy/index.js
refer line number : 64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With