Nicklas A.
Nicklas A.

Reputation: 7061

Push arbitrary data to a Meteor server

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. The deploy script is invoked.
  2. At the end of the script my Meteor server is notified of the deploy by the script.
  3. The server inserts a documents containing information about the deploy.
  4. All clients receive the new document and re-renders.

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.

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

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

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

Upvotes: 0

Views: 234

Answers (1)

Hubert OG
Hubert OG

Reputation: 19544

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

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
    }
  },
});

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.

Upvotes: 1

Related Questions