【发布时间】:2016-06-24 03:21:56
【问题描述】:
为了测试功能,我设置了一些 Netflix OSS 微服务(Eureka、Falcor sidecar)以及一个非常基本的 Falcor 设置。我正在尝试从 Falcor 的客户端调用外部 API,其端点是 http://localhost:8001/customer/customers。在我的index.js 文件中,我有:
app.use('/model.json', falcorExpress.dataSourceRoute(function (req, res) {
return new falcorRouter([
{
route: "customers.length",
get: function (pathset) {
return http.get("http://localhost:8001/customer/customers")
.then(function (json) {
return {
path: pathset,
value: $atom(json.length)
};
});
}
}
]);
}));
然后在我的客户端index.html:
<html>
<head>
<script src="js/falcor.browser.js"></script>
<script>
var model = new falcor.Model({source: new falcor.HttpDataSource('/model.json') });
model.
get("customers.length").
then(function(response) {
console.log(response);
});
</script>
</head>
<body>
</body>
</html>
如果我手动点击http://localhost:8001/customer/customers API,我会得到一个这样的 JSON 对象:
[
{
"customerId": 1,
"customerName": "Pierre"
},
{
"customerId": 2,
"customerName": "Paula"
}
]
但是,我的console.log 正在输出这样的错误对象:
[{path: ["customers","length"],
value: {message: "undefined is not a function"}}]
在这个阶段我对我返回的格式对象不太感兴趣,我只是想要一些可以玩的东西。如何修改我的路由器以获取我期望的数据?
谢谢
【问题讨论】:
标签: node.js falcor falcor-router