【问题标题】:Weinre on heroku在heroku上的Weinre
【发布时间】:2012-06-06 05:34:42
【问题描述】:

我正在尝试在heroku 上设置Weinre,但我遇到了一些问题。

我设法构建了应用程序,只需使用带有 weinre npm 依赖项的 package.json 和如下所示的 Procfile

web: node_modules/weinre/weinre --httpPort $PORT

起初一切似乎都正常,客户端显示了 UI,JS 文件加载正常,但调试不起作用,并且没有客户端出现在服务器端。

在查看日志时,我意识到对于每个包含 /ws/target/* 或 /ws/client/* 的请求,我都会收到 404 错误

2012-05-31T22:37:53+00:00 heroku[router]: GET xxxx.herokuapp.com/target/target-script.js dyno=web.1 queue=0 wait=0ms service=10ms status=200 bytes=190900
2012-05-31T22:37:36+00:00 heroku[router]: GET xxxx.herokuapp.com/ws/target/t-3 dyno=web.1 queue=0 wait=0ms service=3ms status=404 bytes=9
2012-05-31T22:36:39+00:00 heroku[router]: POST xxxx.herokuapp.com/ws/client/c-1 dyno=web.1 queue=0 wait=0ms service=40ms status=404 bytes=9

此设置在本地运行没有问题。

我还用--boundHost 0.0.0.0 尝试了 Procilfe 并得到了同样的错误。当我使用我的 heroku 应用程序域/子域作为主机时,我得到了weinre: error running server: Error: listen EADDRNOTAVAIL 错误

如果需要,您可以在github repo查看源代码

https://github.com/felipesabino/weinre-heroku

编辑: 这可能与 Heroku 不支持 WebSockets 有关: https://devcenter.heroku.com/articles/http-routing#websockets

最奇怪的是,PhoneGap 的 weinre 调试页面也出现了同样的问题 http://debug.phonegap.com/

有人知道怎么解决吗?

【问题讨论】:

  • 你在 Cedar 堆栈上运行吗?

标签: node.js heroku websocket express weinre


【解决方案1】:

目前我已经在 Heroku 上运行,但我记得当我试图让它运行时,它是一场真正的噩梦。

这是使用 weinre 的 2.0.0-pre-H0WVARLU-incubating,所以它可能有点不同,但我必须做的是:

  • 修改 weinre 本身,我必须告诉 weinre 绑定到所有主机,我修改了 cli.coffee 文件并将 boundHost 设置为 -all- 作为默认值
  • 我赞扬了if remoteAddress 签入channelManager.coffee,因为您进来的地址是通过代理重新映射的,并且从未匹配
  • 打开详细调试,虽然您实际上并不需要运行它,但它可以更轻松地跟踪错误发生的位置(以及请求未路由的原因)

我的 Procfile 最终变得非常简单,因为我尝试尽可能将 weinre 用作“本地”(请注意,repo 包含 only weinre,它不是您正在做的模块):

web: node weinre

我将任何端口更改留给 process.env.PORT 处理,而不是从 Procfile 传入

基本上我发现 weinre 并不是为在代理后面工作而设计的!

【讨论】:

  • 太棒了!这是工作!我已经更新了 github 存储库,稍后我将在 README 文件中添加更多“heroku 特定”说明! Tks
  • FWIW 如果您需要远程客户端的 IP,您应该从 X-Forwarded-For 标头中获取它。
【解决方案2】:

查看此拉取请求https://github.com/apache/incubator-cordova-weinre/pull/10

请注意,不需要其他修改,Procfile 可以设置选项(就像它应该的那样)并且 Weinre 被正确用作节点模块。

package.json(包含修复)

"dependencies" : {
    "weinre": "https://github.com/downloads/AppGyver/incubator-cordova-weinre/apache-cordova-weinre-2.0.0-pre-H77LBWIW-incubating-bin.tar.gz"
},

过程文件

web: node_modules/weinre/weinre --httpPort $PORT --boundHost -all- --debug true --verbose true

【讨论】:

  • 太棒了!你有改变在heroku的环境中测试这个拉取请求吗?
  • 感谢 Matti,weinre 得到了“修复”,因此它可以在 Heroku 和其他 PaaS 上轻松运行。我当时写了一篇博文:pmuellr.blogspot.com/2012/11/…
【解决方案3】:
  • 修改 weinre 本身,我必须告诉 weinre 绑定到所有主机,我修改了 cli.coffee 文件并将 boundHost 设置为 -all- 作为默认值
  • 我推荐了 channelManager.coffee 中的 if remoteAddress 检查,因为您输入的地址是通过代理重新映射的,并且从未匹配

这两个提示对 appfog 也有很大帮助

你还需要

  • 将 weinre 重命名为 app.js
  • 需要本地咖啡脚本
  • 将 cli 分配给变量并直接执行运行
  • 扩展 cli.coffee -> 端口为process.env.PORT

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多