I have a server-side route that I use for Facebook share (since it requires a URL nowadays)
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();
});
But my global Router.onBeforeAction()
function still gets called, which uses jQuery (animation) -- this causes problems on the server side.
Is there a way to skip over global hooks or should I just check if jQuery is defined?
According to the iron:router guide, you should declare your global onBeforeAction hook using the except option :
Router.onBeforeAction(yourGlobalHook, {
except: ['share']
});