Heroku No such app error with Node.js node-http-proxy module

ぃ、小莉子 提交于 2019-12-31 20:40:23

问题


I'm trying to redirect traffic from my test app's /api/* url to my api hosted on Heroku.

Therefore, localhost/api/hello should be proxied to testapp.heroku.com/hello and the response returned.

Using node-http-proxy works perfectly on localhost to localhost, but when I point it to myapp.heroku.com, I get this error:

Heroku | No such app
There is no app configured at that hostname.
Perhaps the app owner has renamed it, or you mistyped the URL.

I have a feeling it's Heroku's routing system that's fudging up my proxied request, and I haven't found a way to fix it. Any ideas?


回答1:


I have seen something similar when proxing requests to a different domain. The work around that I used was to modify the host header on the proxy request to match the domain name the remote site expects. So in your case the code would look like:

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


var server = httpProxy.createServer(function (req, res, proxy) {
  req.headers.host = 'myapp.heroku.com';
  proxy.proxyRequest(req, res, {
    port: 80,
    host: 'myapp.heroku.com'
  });
}).listen(9000);

I'd be interested to know if this works for you.



来源:https://stackoverflow.com/questions/6444280/heroku-no-such-app-error-with-node-js-node-http-proxy-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!