Heroku Node.js node-http-proxy模块没有这样的应用程序错误 [英] Heroku No such app error with Node.js node-http-proxy module

查看:105
本文介绍了Heroku Node.js node-http-proxy模块没有这样的应用程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



因此,localhost / api / hello $ b在我的测试应用程序的/ api / * url中将流量重定向到我的api上。 $ b应该代理到testapp.heroku.com/hello
并返回响应。

使用node-http-proxy在localhost到localhost上完美工作,但是当我将它指向myapp.heroku.com时,出现此错误:

  Heroku |没有这样的应用程序
该主机名没有配置应用程序。
也许应用所有者已将其重命名,或者您错误输入了URL。

我感觉Heroku的路由系统正在欺骗我的代理请求,而且我还没有找到一种解决方法。任何想法?

解决方案

当将请求接近不同的域时,我已经看到类似的东西。我使用的工作是修改代理请求上的主机头以匹配远程站点所期望的域名。所以在你的情况下,代码如下所示:

  var http = require('http'),
httpProxy =要求( 'HTTP代理');


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'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?

解决方案

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.

这篇关于Heroku Node.js node-http-proxy模块没有这样的应用程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆