0
votes

I'm working on a meteor app, and as part of it it would be very nice to return some static pages containing JSON.

The JSON they return is generated by running some node (connecting to the Twitter API), however it does not reflect any underlying Meteor collection, so I don't think any of the packages that allow you to build an API on your meteor app would be appropriate.

I can see that one solution is to do this part outside of meteor, however I like the idea of only having one thing to deploy and wondered if there is a solution in meteor, possibly by making a package?

2

2 Answers

0
votes

Yes, as justswim already said in the comments, I think you are looking for something like this:

Router.map(function () {
  this.route('serverFile', {
    path: '/posts/:user',
    where: 'server',
    action: function () {
      var user = this.params.user
      // get your data from Twitter API, e.g., using the HTTP package.
      this.response.end(JSON.stringify(yourobject));
    }
  });
});
0
votes

You can easily define a meteor API using the Meteor iron-router. Just define the route that you want to serve as the call for your api. When a user hits this route, your app will render the corresponding template (in which you can place the static json).

In your Router's map function, you might have something like this:

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