Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http proxy error for target

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
                },

        });
like image 980
07_05_GuyT Avatar asked Jul 28 '15 10:07

07_05_GuyT


1 Answers

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

like image 95
dayakar Avatar answered Sep 20 '22 10:09

dayakar