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?
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 ()
});
You can achieve this with the Meteor Router smart package:
Meteor.Router.add({
'/callback': 404
})
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With