Falcor路由特定中间件
Falcor route specific middleware
给定服务器上运行的Router类:
var PetsRouterBase = Router.createClass([{
route: 'petList[{integers:indices}].name',
get: function(pathSet) {
return [
{
path: ['petList', 0, 'name'],
value: 'Pets I have now'
},
{
path: ['petList', 1, 'name'],
value: 'Pets I once had'
},
{
path: ['petList', 2, 'name'],
value: 'Pets my friends have'
}
];
}
}]);
以及浏览器中的以下路径查询(我使用的是falco -http-datasource):
model.get('petList[0..2].name');
我得到了正确的数据:
{
"jsonGraph": {
"petList": {
"0":{"name":"Shows of Artists I've been to before",
"1":{"name":"Shows of artists my friends have been to before",
"2":{"name":"Highly rated artists"}
}
}
}
我的问题是,在服务器上,是否有一种方法可以让我访问falcor在响应此get路由请求时通过有线发送回浏览器的实际结果?
我的用例是我想一起注销两段数据:
- 路由通过的路径集。
- falcor通过网络发回的json结果。
我在想它可能看起来像这样:
var PetsRouterBase = Router.createClass([{
route: 'petList[{integers:indices}].name',
done: function(pathSet, results) {
// Log out the result of the lookup
console.log(pathSet, results);
},
get: function(pathSet) {
return [
{
path: ['petList', 0, 'name'],
value: 'Pets I have now'
},
{
path: ['petList', 1, 'name'],
value: 'Pets I once had'
},
{
path: ['petList', 2, 'name'],
value: 'Pets my friends have'
}
];
}
}]);
澄清一下。我知道我可以在客户端得到结果,但我想把它们管道到服务器的其他地方。
目前最简单的方法是在将路由器发送给快速中间件之前装饰它。
app.use('/model.json', FalcorServer.dataSourceRoute(function(req, res) {
return {
get: function(pathSets) {
// print incoming paths to console
console.log(JSON.stringify(pathSets, null, 4));
return router.
get(pathSets).
// print the results to the console
doAction(function(output) {
console.log(JSON.stringify(output, null, 4));
});
}
};
})
相关文章:
- 什么'在Express中路由时,应用程序级中间件和路由器级中间件之间的区别是什么
- Expressjs:如何跨路由共享路由中间件
- 节点-如何在POST路由中间件中访问请求
- 使用虚拟主机中间件在 Express 中按子域指定路由
- 快速 - 路由中间件 如何确定响应视图是否已呈现
- Express JS - 对路由和中间件使用匿名函数
- 如何将快速路由处理传递给下一个中间件并破坏当前代码块
- Express :如何将中间件独占添加到路由器对象中的大型路由列表中
- 禁用特定路由上特定谓词的身份验证中间件
- NodeJs 路由中间件错误
- Express v4:如何在参数中间件之前运行特定于路由的中间件
- 创建路由得到 Router.use() 的错误需要中间件功能
- 从快速中间件中排除路由
- 在任何路由之前运行的中间件
- 通过Express中间件将req.body传递到路由
- 在nodejs中使用带有handlerbs的路由中间件
- Express.js:从路由处理程序中调用next(error)会调用全局错误处理中间件吗?
- NodeJS Express Router,在中间件和路由之间传递解码后的对象
- Falcor路由特定中间件
- 重新定义中间件,如指定路由的express中间件