Pergunta

im using following code for http-proxy:

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

var options = {
    router: {
    '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

Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top