我可以通过 __meteor_bootstrap__.app 挂载另一个路由处理程序吗? [英] Can I mount another route handler through __meteor_bootstrap__.app?
问题描述
我正在构建我的第一个流星应用程序,需要能够创建一个新的路由处理程序来处理 oauth 回调.我查看了 server.js,发现 connect.app 上下文在 meteor_bootstrap 下可用.虽然这似乎不起作用:
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;
});
});
}
想法?
推荐答案
这个解决方案的问题是你的中间件被放在了堆栈的底部.因此,包罗万象的流星处理程序将始终在您的/回调"处理程序之前运行.
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.
解决此问题的一种非常hacky 的方法(直到流星释放其适当的路由支持)是将处理程序拼接到堆栈顶部:
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屋!