Is there a way to return straight text in a page using meteor? Say someone requested domain.com/get/that-thing, and I just wanted to return the string "52", so that the requester knows that-thing has "52" of something. To my understanding, this is not possible in Meteor because the headers and such are always included.
2 hacks that would work: Write to a file named "that-thing" in anticipation that "that-thing" might be called. This doesn't work in the general case. Put a reverse proxy that redirects some of the requests to a non-meteor backend.
Is there a better way to do this?
I had to solve this today and using Iron-Router server-side-routing: https://github.com/EventedMind/iron-router/blob/master/DOCS.md#server-side-routing
Simple example:
Router.map(function () {
this.route('api', {
path: '/api',
where: 'server',
action: function () {
var json = Collection.find().fetch(); // what ever data you want to return
this.response.setHeader('Content-Type', 'application/json');
this.response.end(JSON.stringify(json));
}
});
});
This will return a valid JSON "page" which you can then use how ever you want.
Thanks to @Akshat for answering: Meteor Iron-Router Without Layout Template or JSON View
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With