我可以通过__meteor_bootstrap__.app挂载另一个路由处理程序吗? [英] Can I mount another route handler through __meteor_bootstrap__.app?
问题描述
我正在构建我的第一个流星应用程序,需要能够创建一个新的路由处理程序来处理oauth回调.我查看了server.js,发现在 meteor_bootstrap 下可以使用connect.app上下文.尽管这似乎不起作用:
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;
});
});
}
有想法吗?
推荐答案
此解决方案的问题是您的中间件位于堆栈的底部.因此,包罗万象的流星处理程序将始终在您的"/callback"处理程序之前运行.
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 ()
});
这篇关于我可以通过__meteor_bootstrap__.app挂载另一个路由处理程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!