将任意数据推送到 Meteor 服务器 [英] Push arbitrary data to a Meteor server

查看:58
本文介绍了将任意数据推送到 Meteor 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个仪表板,显示自我们上次部署服务以来的时间.

I'm trying to make a dashboard that shows the time since our services were last deployed.

这是我计划使用的产品:

This was the produce I was planning to use:

  1. 调用部署脚本.
  2. 在脚本结束时,脚本会通知我的 Meteor 服务器部署.
  3. 服务器插入包含有关部署信息的文档.
  4. 所有客户端都会收到新文档并重新渲染.

我遇到的唯一问题是第 2 步.

The only problem I'm having is with step #2.

最好的方法是如果服务器可以以某种方式订阅并且客户端可以发布但服务器似乎不支持订阅.

The nicest way to do this would be if the server could somehow subscribe and client could publish but servers doesn't seem to support subscriptions.

另一种选择是自己实现 DDP,但如果不在浏览器中,这可能并不容易.

Another options is to implement DDP yourself but that is probably not that easy when not in a browser.

我看过一些 meteor-collectionapi,它是 Meteor 的 REST API,但是感觉这会违反 Meteor 原则,并且在使用 Meteor 0.6.5 时似乎也被破坏

I've looked a bit at meteor-collectionapi which is a REST API for Meteor but it feels like that would be violating the Meteor principles and it also appears to be broken when using Meteor 0.6.5

所以我的问题是,如何以 Meteor 方式通知服务器更改?

So my question is really, how do notify a server of changes the Meteor way?

推荐答案

REST API 没有任何问题.毕竟,HTTP 是 Web 服务器对话的主要语言.

There's nothing wrong with a REST API. After all, HTTP is the main language web server talks.

在服务器端,按如下方式监听(0.6.5代码):

On the server, listen in the following way (0.6.5 code):

WebApp.connectHandlers.stack.splice(0,0,{
  route: '/some/long/secret/route',
  handle: function(req, res, next) {
    if(req.method === 'POST') {
      // Listen for deploy information
      // Insert info to DB
    }
  },
});

然后你就可以curl正确的地址并提供你想要的任何数据.建议在 POST 参数中包含一个安全密码,这样一些幸运的爬虫不会留下不必要的数据.

And then you can just curl the right address and give any data you want. It's recommended to include a security secret as one of POST parameters, so that some lucky crawler won't leave unnecessary data.

这篇关于将任意数据推送到 Meteor 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆