【问题标题】:mup deploy errors when using webapp.connecthandlers使用 webapp.connecthandlers 时 mup 部署错误
【发布时间】:2016-01-02 10:30:24
【问题描述】:

我正在尝试在访问我的“www”网址以重新路由到“非 www”时实现 301 重定向。重定向在本地主机上工作,项目构建良好。当我尝试使用 mup 进行部署时,出现此错误:

x Invoking deployment process: FAILED

    -----------------------------------STDERR-----------------------------------
    :callback’ will be initialized after [-Wreorder]
           v8::Handle<v8::Function> callback;
                                    ^
    ../src/heap_output_stream.h:26:29: warning:   ‘v8::Handle<v8::Value> nodex::OutputStreamAdapter::abort’ [-Wreorder]
           v8::Handle<v8::Value> abort;
                                 ^
    ../src/heap_output_stream.h:11:7: warning:   when initialized here [-Wreorder]
           OutputStreamAdapter(
           ^
    gyp info ok 
    npm WARN package.json meteor-dev-bundle@0.0.0 No description
    npm WARN package.json meteor-dev-bundle@0.0.0 No repository field.
    npm WARN package.json meteor-dev-bundle@0.0.0 No README data
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to localhost port 80: Connection refused
    Latest deployment failed! Reverted back to the previous version.

这是有问题的代码。当我删除它时,mup 工作正常。 此代码位于/lib/_reroute-non-www.js

if( Meteor.isServer ){
  WebApp.connectHandlers.use(function(req, res, next){
    if( req.headers.host == 'www.example.com' ){
      res.writeHead(301, {
        Location: 'https://example.com'
      })
      res.end()
    } else {
      next()
    }
  })
}

这是什么意思?

【问题讨论】:

  • 错误提示“无法连接到本地主机端口 80:连接被拒绝”。问题可能是在您的服务器上它不能使用端口 80,除非您以 root 身份运行它。在 Windows 上,它在端口 80 上运行正常,不幸的是在 Linux 上没有。
  • 这并不能真正解释为什么这个问题在使用WebApp.connectHandlers 代码时会发生。 :(
  • 所以 WebApp.connectHandlers 正在尝试连接到 localhost:80。这是它应该做的吗?不知道 connectHandlers 的作用是很难提供帮助的。
  • WebApp.connectHandlers 是一种在流星应用程序docs.meteor.com/#/full/webapp 中连接到 node.js 中的 Web 服务器中间件的方法

标签: javascript node.js meteor meteor-up


【解决方案1】:

虽然我不完全确定为什么这组特定代码会导致 mup 像这样“呕吐”,但我确实找到了其他可能相关的原因。

当使用 RabbitMQ(通过Wascally)时,我的消费者处理程序必须使用注册

Fiber(()=>{
  rabbit.handle(key, consumerFn)
}).run()

...在consumeFn() 内部,我没有可用的 Meteor 环境!没有Meteor,而且我无权访问可能已在我的应用程序中定义的任何集合。

我能够做的是在我的then 处理程序上使用Meteor.bindEnvironment,这是我注册处理程序时返回的承诺。使用 Meteor.bindEnvironment 可以让我访问我希望在 Meteor 应用程序中拥有的所有内容。

Wascally.request(key, {content: 'my content'})
  .then(Meteor.bindEnvironment((result)=>{
    // now i have access to my Meteor environment and all collections
  }))

【讨论】:

    猜你喜欢
    • 2017-08-05
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 2016-11-27
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    相关资源
    最近更新 更多