【问题标题】:Heroku No such app error with Node.js node-http-proxy moduleHeroku Node.js node-http-proxy 模块没有这样的应用程序错误
【发布时间】:2011-09-20 14:50:36
【问题描述】:

我正在尝试将流量从我的测试应用的 /api/* url 重定向到我在 Heroku 上托管的 api。

因此,localhost/api/hello 应该代理到 testapp.heroku.com/hello 并返回响应。

在 localhost 到 localhost 上使用 node-http-proxy 可以完美运行,但是当我将它指向 myapp.heroku.com 时,我收到此错误:

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

我感觉是 Heroku 的路由系统在伪造我的代理请求,我还没有找到解决方法。有什么想法吗?

【问题讨论】:

    标签: node.js proxy heroku http-proxy


    【解决方案1】:

    在将请求代理到不同域时,我看到了类似的情况。我使用的解决方法是修改代理请求上的主机头以匹配远程站点期望的域名。因此,在您的情况下,代码如下所示:

    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);
    

    我很想知道这是否适合你。

    【讨论】:

    • 完美运行。在标题中设置主机修复了它。出于某种原因,我认为 http-proxy 会这样做。感谢您使我免于使用肮脏的 cURL hack!谢谢!
    • http-proxy 支持一个 changeOrigin 选项来处理这个问题。 github.com/nodejitsu/node-http-proxy#http-proxy
    • 我确实发现并做了同样的事情。
    猜你喜欢
    • 2012-10-28
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 2012-08-25
    • 2016-01-04
    相关资源
    最近更新 更多