我可以通过 __meteor_bootstrap__.app 挂载另一个路由处理程序吗? [英] Can I mount another route handler through __meteor_bootstrap__.app?

查看:12
本文介绍了我可以通过 __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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆