Proxy server with Node.js on Heroku

后端 未结 2 1668
长发绾君心
长发绾君心 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.

    0 讨论(0)
  • 2020-12-31 23:55

    I use http-proxy successfully on Heroku. The first thing I noticed in your log err is the url it is GETting: GET lelylan-api.herokuapp.com/tdevices

    There is a typo... instead of '/devices' it shows '/tdevices'. Before continuing can you confirm this is the actual log message?

    0 讨论(0)
提交回复
热议问题