In the company using NODEJS to build proxy server to achieve the separation of the front and back, the code can not be taken out, and then appear httpproxy agent resources always appear 404. The interface is clearly represented. The code is probably as follows:
var http = require (' http '),
httpproxy = require (' Http-proxy ');
var proxy = Httpproxy.createproxyserver ({});
var server = Http.createserver (function (req, res) {
proxy.web (req, res, {target: ' http://www.cnblogs.com/xiaopen/') });
});
Console.log ("Listening on port 5050")
Server.listen (5050);
And then an error or 404 wrong code.
Solution:
In the proxy request, remove the host in the request header and improve the code as follows:
var http = require (' http '),
httpproxy = require (' Http-proxy ');
var proxy = Httpproxy.createproxyserver ({});
var server = Http.createserver (function (req, res) {
delete req.headers.host;
Proxy.web (req, res, {target: ' http://www.cnblogs.com/xiaopen/'});
}
; Console.log ("Listening on port 5050")
Server.listen (5050);
And then run correctly as scheduled.
The above use of the Nodejs httpproxy agent when 404 unusual solution is to share all the content of the small, hope to give you a reference, but also hope that we support the cloud habitat community.