Proxy server with Node.js on Heroku

后端 未结 2 1673
长发绾君心
长发绾君心 2020-12-31 23:23

I\'m trying to build a proxy server on with Node.js on Heroku using http-proxy. Everything works fine locally, but I\'m having some troubles on Heroku.

var          


        
2条回答
  •  佛祖请我去吃肉
    2020-12-31 23:43

    I finally made it work using a slightly modified version proxy-by-url. The final code looks something like this and works fine.

    var httpProxy = require('http-proxy');
    
    var port = process.env.PORT || 8000;
    
    var routing = {
      '/devices': { port: process.env.DEVICES_PORT || 80, host: process.env.DEVICES_URI }
    }
    
    var server = httpProxy.createServer(
      require('./lib/uri-middleware')(routing)
    ).listen(port);
    

    One note to remember. The plugin sets the header HOST to the destination application uri. If you do not do so, Heroku will not recognize the app and will not find it, as its internal routing system seems to be based on the HOST header.

提交回复
热议问题