如何解决如何使用http-proxy使下面的代码创建代理服务器,发送请求,并获得对外界的响应?
var http = require('http'),httpProxy = require('http-proxy');
//
// Create a proxy server with custom application logic
//
var proxy = httpProxy.createProxyServer({});
//
// Create your custom server and just call `proxy.web()` to proxy
// a web request to the target passed in the options
// also you can use `proxy.ws()` to proxy a websockets request
//
var server = http.createServer(function(req,res) {
// You can define here your custom logic to handle the request
// and then proxy the request.
proxy.web(req,res,{ target: 'http://127.0.0.1:5050' });
});
console.log("listening on port 5050")
server.listen(5050);
是否应该在 localhost
、端口 5050
创建一个代理服务器,以便将流量路由到外部世界并获得响应?
如果我运行这个程序,并在 Firefox 中设置为使用代理“本地主机和端口 5050”并尝试不使用 https 的网站之一,例如 http://apache.org/ 上面的程序会崩溃错误:
listening on port 5050
/Users/peter/code/node_modules/http-proxy/lib/http-proxy/index.js:120
throw err;
^
Error: connect EMFILE 127.0.0.1:5050 - Local (undefined:undefined)
at internalConnect (net.js:908:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:301:12)
at net.js:999:9
at processticksAndRejections (internal/process/task_queues.js:75:11) {
errno: 'EMFILE',code: 'EMFILE',syscall: 'connect',address: '127.0.0.1',port: 5050
}
如何让它发挥作用?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。