git://www.github.com/Netflix/falcor.git
git clone http://www.github.com/Netflix/falcor
$ svn co --depth empty http://www.github.com/Netflix/falcor
Checked out revision 1.
$ cd repo
$ svn up trunk
2.0.0 是当前稳定的Falcor发行版。 欢迎使用英镑 0.x 和英镑 1.x 用户升级。
Breaking 1.x 和英镑之间的重大变更可以在这里查看 。
Breaking 0.x 和英镑之间的重大变更可以在这里查看 。
我们作为路线图的一部分跟踪的问题被标记为路线图标签。 我们可以把它们分成增强,稳定性,性能,工具,工具,基础结构,以及我们计划实现它们的更广泛的顺序的。
现在,你可以在这里查看一个类似于应用程序的工作示例服务器。 或者你可以通过这个骨干教程,我们使用Falcor路由器来创建一个虚拟JSON资源。 在本教程中,我们将使用falcor中间件的表示来在 URL /model.json
上服务应用服务器上的虚拟JSON资源。 我们还将在同一台服务器上托管 static 网页,该服务器从虚拟JSON资源检索数据。
在这个例子中我们将使用falcor路由器在应用服务器上构建一个虚拟JSON资源,并在 /model.json
上托管它。 JSON资源将包含以下内容:
{ "greeting":"Hello World"}
通常路由器从后端数据存储或者其他 Web服务 中检索它们的虚拟JSON资源的数据。 然而在这个简单的教程中,路由器将只返回单个键的static 数据。
首先我们为应用服务器创建一个文件夹。
mkdir falcor-app-servercd falcor-app-server
npm init
现在我们安装falcor路由器。
npm install falcor-router --save
然后安装express和 falcor-express 。 同时也支持 restify,也支持通过第三方实现工具支持 hapi 。
npm install express --save npm install falcor-express --save
现在,我们创建一个包含以下内容的index.js 文件:
// index.jsvar falcorExpress =require('falcor-express');var Router =require('falcor-router');var express =require('express');var app =express();app.use('/model.json', falcorExpress.dataSourceRoute(function (req, res) { // create a Virtual JSON resource with single key ("greeting")returnnewRouter([ { // match a request for the key"greeting" route:"greeting", // respond with a PathValue with the value of"Hello World."get:function() { return {path:["greeting"], value:"Hello World"}; } } ]); }));// serve static files from current directoryapp.use(express.static(__dirname+'/'));var server =app.listen(3000);
现在我们运行服务器,它将监听端口 3000,用于 /model.json
的请求。
node index.js
现在我们已经构建了一个只读只读密钥 greeting
的简单虚拟JSON文档,我们将创建一个测试网页并从服务器检索这个密钥。
创建一个包含以下内容的index.html
文件:
<!-- index.html --><html> <head> <!-- Do _not_ rely on this URL in production. Use only during development. --> <scriptsrc="https://netflix.github.io/falcor/build/falcor.browser.js"></script> <!-- For production use. --><!-- <script src="https://cdn.jsdelivr.net/falcor/{VERSION}/falcor.browser.min.js"></script> --> <script>var model =falcor({source:newfalcor.HttpDataSource('/model.json') });// retrieve the"greeting" key from the root of the Virtual JSON resource model.get("greeting").then(function(response) {document.write(response.json.greeting); });</script> </head> <body> </body> </html>
现在访问 http://localhost:3000/index.html
,你应该看到从服务器检索到的消息:
Hello World
为了详细解释模型,路由器和JSON图查看了 Falcor网站 。
对于API文档,请在这里转到 。
有关路由器的工作示例,请查看 falcor-router-demo 。
有关问题和讨论,请使用堆栈 overflow 。