2016-09-01 210 views
0

有没有办法让流星厨房在服务器端渲染?流星厨房服务器端渲染

目前它呈现所有通过javascript,但我也打算建立一个REST API,所以我需要服务器端渲染。

回答

0

你可以使用meteorhacks完成服务器端渲染:ssr + iron:router。你在服务器端创建一个铁路线,然后渲染火焰模板。这是一个示例路线。

this.route('home', { 
    where: 'server, 
    path: '/', 
    action: function() { 
     var templateData = {}; 
     var html = SSR.render('templateName', templateData); 
     this.response.writeHead(200, {'Content-Type': 'text/html'}); 
     this.response.write(html); 
     this.response.end(); 
    } 
}); 

我正在使用此方法为https://gameraven.com/上的SEO提供静态页面。

+0

谢谢Derrick的回复,但是你可以扩展这个答案,在这段代码去哪里? – chulian

+0

该代码可以在服务器/ main.js 我建议你通读这两个包的文档。 https://github.com/iron-meteor/iron-router and https://github.com/meteorhacks/meteor-ssr –