Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
服务';静态';使用Meteor的节点页面_Meteor - Fatal编程技术网

服务';静态';使用Meteor的节点页面

服务';静态';使用Meteor的节点页面,meteor,Meteor,我正在开发一个meteor应用程序,作为其中的一部分,返回一些包含JSON的静态页面会非常好 他们返回的JSON是通过运行某个节点(连接到Twitter API)生成的,但是它并不反映任何基础Meteor集合,因此我认为任何允许您在Meteor应用程序上构建API的包都不合适 我可以看到一个解决方案是在meteor之外完成这一部分,但是我喜欢只部署一件事情的想法,并且想知道meteor中是否有解决方案,可能是通过制作一个包?您可以使用。只需定义要用作api调用的路由。当用户点击此路径时,您的应用

我正在开发一个meteor应用程序,作为其中的一部分,返回一些包含JSON的静态页面会非常好

他们返回的JSON是通过运行某个节点(连接到Twitter API)生成的,但是它并不反映任何基础Meteor集合,因此我认为任何允许您在Meteor应用程序上构建API的包都不合适


我可以看到一个解决方案是在meteor之外完成这一部分,但是我喜欢只部署一件事情的想法,并且想知道meteor中是否有解决方案,可能是通过制作一个包?

您可以使用。只需定义要用作api调用的路由。当用户点击此路径时,您的应用程序将呈现相应的模板(您可以在其中放置静态json)

在路由器的映射功能中,您可能有如下内容:

Router.map(function () {
  /**
   * The route's name is "jsonTemplate"
   * The route's template is also "jsonTemplate"
   * The template will be rendered at http://yourapp.com/apiEndpoint
   */
  this.route('jsonTemplate', {
    path: '/apiEndpoint',
    template: 'jsonTemplate'
  });
});

是的,正如justswim在评论中所说的那样,我认为你正在寻找这样的东西:

Router.map(function () {
  /**
   * The route's name is "jsonTemplate"
   * The route's template is also "jsonTemplate"
   * The template will be rendered at http://yourapp.com/apiEndpoint
   */
  this.route('jsonTemplate', {
    path: '/apiEndpoint',
    template: 'jsonTemplate'
  });
});
Router.map(函数(){
此.route('serverFile'{
路径:'/posts/:user',
其中:'服务器',
行动:功能(){
var user=this.params.user
//从Twitter API获取数据,例如使用HTTP包。
end(JSON.stringify(yourobject));
}
});
});

这非常有帮助,谢谢。您是否知道在模板中呈现JSON是否有一种好方法?这取决于您如何创建/获取JSON。一种方法是使用handlebar变量,然后在客户端javascript中定义JSON。也就是说,在模板中有一个变量,如
{{myJson}
,在javascript中定义变量,如
template.myTemplate.myJson=function(){return getJSONdata()}
,我明白了,所以现在我想这是行不通的,因为当服务使用API时,它不会运行JS。整个事情都必须呈现在服务器端…我明白了。嗯,你看过Iron路由器文档中关于服务器端路由的部分了吗?很酷,我希望可以。我对您是需要为静态客户端页面服务还是需要向服务器端发送信息感到困惑。我认为@ChristianF在下面发布了一个很好的例子。