2016-09-01 207 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 –