2015-07-01 75 views
0

長話短說,我得到這個deployd「server.js」Deployd和通用/同構的應用程序做出反應

var deployd = require('deployd'); 
... 
var server = deployd(options); 
server.listen(); 

再有就是「公共」文件夾,我的應用程序做出反應駐留在右鍵現在我只是用數據庫的API的Deployd,但我希望應用程序是同構的(所以搜索引擎可以索引)。

所有示例似乎都使用Express或Koa作爲服務器,而Mongoose/Koa-mongo-rest用於某種API連接,但這似乎是Deployd已經處理的大量工作。我想只使用視圖的React,Flux的Alt和Deployd的API /服務器/ whatnot。但我真的很初學這個,不知道如何拿一個樣板和切換服務器。特別是使用Deployd時,所有「React應用程序」都將駐留在「公共」目錄中,但對我來說,似乎我需要移動1個高於該目錄的目錄,並在部署的server.js中「呈現」該應用程序以便它可以是同構的/通用的。或者我只是離開服務器而只需要做別的事情?

基本上我並不真正掌握同構渲染的概念在所有... ELI5,我不是一個聰明的人...

編輯:看起來你可以運行deployd作爲快遞中間件,我想我可以弄清楚如何做...

回答

1

如果您使用deployd作爲快遞中間件,則可以使用PayPal的react-engine作爲呈現React的快速視圖系統。

var express = require('express'); 
var app = express(); 

// create the view engine with `react-engine` 
var engine = require('react-engine').server.create({ 
    reactRoutes: <string> /* pass in the path to react-router routes optionally */ 
    performanceCollector: <function> /* optional function to collect perf stats */ 
}); 

// set the engine 
app.engine('.jsx', engine); 

// set the view directory 
app.set('views', __dirname + '/views'); 

// set jsx as the view engine 
// Without this you would need to 
// supply the extension to res.render() 
// ex: res.render('index.jsx'). 
app.set('view engine', 'jsx'); 

// finally, set the custom view 
app.set('view', require('react-engine/lib/expressView')); 
相關問題