7

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?

manalang
  • 805
  • 1
  • 6
  • 10

3 Answers3

8

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 ()
});
wkz
  • 2,203
  • 1
  • 15
  • 21
  • 4
    This shouldn't be necessary after the following change: https://github.com/meteor/meteor/commit/a2d5bfa6dbbecff94877142a57bb212aa7f2a590 – avital Aug 20 '12 at 07:43
  • +1 for noticing this and also for the Meteor code change. Can you clarify how that helps, though? – Andrew Mao Jun 26 '13 at 03:14
6

You can achieve this with the Meteor Router smart package:

Meteor.Router.add({
  '/callback': 404
})
Tom Coleman
  • 3,037
  • 18
  • 16
2

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.

Matt Gaidica
  • 554
  • 5
  • 14