开发者

Node-http-proxy dynamic routetable?

im using following code for http-proxy:

var httpProxy = require('http-proxy');

var options = {
    r开发者_高级运维outer: {
    'url1.com': '127.0.0.1:3000',
    'url2.com': '127.0.0.1:3001'
    }
};

httpProxy.createServer(options).listen(80);

My question is, can i update the routetable dynamically? Without shuting down proxy server?

Thx for answers


For everyone facing that problem, finally i got the solution out of the box. Its all possible, if u pass a string pointing to a file, instead of passing an object as arg. I'll give an example and it should be clear.

proxy.js:

var httpProxy = require('http-proxy');
var options   = { router: 'table.json' };

httpProxy.createServer(options).listen(80);

As u see here, i pass table.json as router option. So look inside that file.

table.json:

{
   "router":
   {
      "domain1.com": "127.0.0.1:8080",
      "domain2.com": "127.0.0.1:8001"
   }
}

And thats the whole magic. node-http-proxy will monitor that file, and if you do any changes on it, it will update its routetable automatically.

Greetings


Yes, but not using the ProxyTable. I've documented an alternative to http-proxy's ProxyTable called 'Switchboard' that does what you want it to do. You'll have to re-arrange some of the features to initialize the paths and backend targets properly, but it should be a straightforward operation, and the backendTable object is dynamically available at runtime.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜