在服务器端路由上避免全局onBeforeAction方法

时间:2015-01-12 20:16:24

标签: javascript meteor iron-router

我有一个服务器端路由,我用于Facebook共享(因为它现在需要一个URL)

this.route('share',{
    path: '/share',
    where: 'server'
}).get(function(data){
    var query = data.query;

    this.response.write('<html>');
    this.response.write('<head>');
    // content type is text/html by default
    this.response.write('<title></title>');

    if(query){
        for(var prop in query){
            if(query.hasOwnProperty(prop)){
                this.response.write('<meta property="'+prop+'" content="'+query[prop]+'" />');
            }
        }
    }

    this.response.write('</head>');
    this.response.write('<body></body>');
    this.response.write('</html>');

    this.response.end();
});

但我的全局Router.onBeforeAction()函数仍然被调用,它使用jQuery(动画) - 这会导致服务器端出现问题。

有没有办法跳过全局钩子或者我应该检查是否定义了jQuery?

1 个答案:

答案 0 :(得分:1)

根据iron:router guide,你应该使用except选项声明你的全局onBeforeAction钩子:

Router.onBeforeAction(yourGlobalHook, {
  except: ['share']
});
相关问题