Для https://www.npmjs.com/package/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 использование прокси-сервера localhost и порта 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
}
Как заставить его работать?