5

i'm trying to implement a 301 redirect when visiting my "www" url to reroute to "non-www". the redirect works on localhost and the project builds fine. when i try to deploy with mup, i get this error:

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.

here is the offending code. mup works fine when i remove it. this codes lives in /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()
    }
  })
}

what does it all mean?

rkstar
  • 1,178
  • 14
  • 27
  • The error says "Failed to connect to localhost port 80: Connection refused" . The problem could be that on your server it can't use port 80 unless you run it as root. On windows it runs OK on port 80 unfortunately not on Linux. – Molda Oct 05 '15 at 17:38
  • that doesn't really explain why this problem _only_ happens when using the `WebApp.connectHandlers` code tho. :( – rkstar Oct 05 '15 at 18:43
  • So WebApp.connectHandlers is trying to connect to localhost:80. Is that what it is supposed to do? It's hard to help without knowing what connectHandlers does. – Molda Oct 05 '15 at 18:48
  • WebApp.connectHandlers is a way to connect to the web server middleware in node.js inside a meteor application https://docs.meteor.com/#/full/webapp – rkstar Oct 06 '15 at 16:45

1 Answers1

0

While I'm not entirely sure why this particular set of code is causing mup to "throw up" like this, I did find other reasons that may be related.

When using RabbitMQ (via Wascally), my consumer handlers have to be registered by using

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

... and inside consumeFn() I DO NOT have the Meteor environment available! There is no Meteor and I do not have access to any collections that may have been defined in my application.

What I was able to do is use Meteor.bindEnvironment on my then handler of a promise that was returned when I registered the handler. Using Meteor.bindEnvironment gives me access to all those things that I expect to have inside my Meteor app.

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