Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I mount another route handler through __meteor_bootstrap__.app?

Tags:

meteor

I'm building my first meteor app and need to be able to create a new route handler to handle an oauth callback. I've looked through server.js and found that the connect.app context is available under meteor_bootstrap. Although this doesn't seem to work:

if (Meteor.is_server) {
  Meteor.startup(function () {
    var app = __meteor_bootstrap__.app;
    app.use('/callback',function (req,res) {
      res.writeHead(404);
      res.end();
      return;
    });
  });
}

Thoughts?

like image 426
manalang Avatar asked Apr 12 '12 08:04

manalang


3 Answers

The problem with this solution is that your middleware is put at the bottom of the stack. Therefore the catch-all meteor handler will always run before your "/callback"-handler.

One very hacky way to get around this (until the meteor releases their proper routing support) is to splice in your handler att the top of the stack:

__meteor_bootstrap__.app.stack.splice (0, 0, {
    route: '/hello',
    handle: function (req,res, next) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end("hello world");
        return;
    }.future ()
});
like image 65
wkz Avatar answered Sep 19 '22 23:09

wkz


You can achieve this with the Meteor Router smart package:

Meteor.Router.add({
  '/callback': 404
})
like image 39
Tom Coleman Avatar answered Sep 23 '22 23:09

Tom Coleman


Some of the answers are leading to routing being a no-go on the server right now without being hacky. It's a known issue, and sounds like routing is a hot item on the todo list.

like image 37
Matt Gaidica Avatar answered Sep 20 '22 23:09

Matt Gaidica