[英]NodeJs Proxy Server Connections
I have written a code so that the the main server connects to the proxy server and it goes on. 我编写了一个代码,以便主服务器连接到代理服务器,然后继续进行。 I need the server to proxy the requests asynchronously but the problem I am facing is that I need to refresh the page.
我需要服务器异步代理请求,但是我面临的问题是我需要刷新页面。 Here is the code
这是代码
var dirServer = httpProxy.createServer(function (req, res, proxy) {
var randNum = Math.floor(Math.random()*6);
console.log(randNum);
proxy.proxyRequest(req, res, {
host: creds[randNum].host,
port: creds[randNum].port
});
console.log("Proxying the request to host : " + creds[randNum].host + ' ' + "Proxying the request to port" + creds[randNum].port);
}).listen(7874, "0.0.0.0");
I have a creds.json file in which it has the names, host and ports of the server. 我有一个creds.json文件,其中包含服务器的名称,主机和端口。
If I have understood your problem correctly, you want a new proxy connection to be made every x seconds, the following code should help 如果我正确理解了您的问题,则希望每隔x秒建立一个新的代理连接,以下代码应该会有所帮助
setInterval(function() {
var dirServer = httpProxy.createServer(function (req, res, proxy) {
var randNum = Math.floor(Math.random()*6);
console.log(randNum);
proxy.proxyRequest(req, res, {
host: creds[randNum].host,
port: creds[randNum].port
});
console.log("Proxying the request to host : " + creds[randNum].host + ' ' + "Proxying the request to port" + creds[randNum].port);
}).listen(7874, "0.0.0.0");
}, 2000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.