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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.