【发布时间】:2020-11-24 14:36:00
【问题描述】:
我正在使用节点模块来创建 http 代理服务器(node-socks),如下所示:
const { http } = require('@sansamour/node-socks')
http.createServer({
authorization: function(u,p){
return u == 'KeemROH' && p == 'Test'
},
port: 5000
});
http.createServer({
authorization: function(u,p){
return u == 'KeemROH' && p == 'Test'
},
port: 5001
});
http.createServer({
authorization: function(u,p){
return u == 'KeemROH' && p == 'Test'
},
port: 5002
});
http.createServer({
authorization: function(u,p){
return u == 'KeemROH' && p == 'Test'
},
port: 5003
});
http.createServer({
authorization: function(u,p){
return u == 'KeemROH' && p == 'Test'
},
port: 5004
});
是否有可能制作一个可以运行的循环:
http.createServer({
authorization: function(u,p){
return u == 'KeemROH' && p == 'Test'
},
port: 5000 // add +1 each loop so 5000, 5001, 5002, 5003, 5004 ect.
});
让它循环一定次数? 因此,与其重写多次,这可能是解决方案
【问题讨论】:
-
let port = 5000; http.createServer({..., port: port++});? -
@HereticMonkey 不幸的是这不起作用
-
当然,对于您发布的代码,循环应该是微不足道的。请向我们展示您的尝试。
-
不清楚您所说的“持续”是什么意思。您的循环需要在某个时候停止(在您的示例中为 5005)。另外,你为什么要创建多个代理服务器?
-
@Bergi 在我的情况下,这个数字可能被配置为在我的应用程序中允许一定数量的端口
标签: javascript node.js loops http proxy