Reputation: 2887
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
},
});
Upvotes: 6
Views: 1103
Reputation: 66
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
Upvotes: 4
Reputation: 644
It's because it only works with string. From https://github.com/nodejitsu/node-http-proxy#options:
httpProxy.createProxyServer supports the following options:
target: url string to be parsed with the url module
Upvotes: 3