Using Meteor.js, how can I serve an arbitrary HTTP response, for example. image or pdf?
Example 1 - I need to create PDF reports that I cannot store publicly or on a third-party server. Or a report can be generated in real time in response to an HTTP GET.
Example 2 - If I have a URL:
/images/myimage.png
I would like to detect this request on the server, read the image from MongoDB and execute it with the correct headers, so it is available for use with img tags, i.e.
<img src="/images/myimage.png">
I do not want to store the images in the / public / directory, so that I can have more control over what is served and how it is allowed.
Change I also managed to get a basic example of working with Iron Router.
ImageController = RouteController.extend({ run: function() { var f = fs.readFileSync("/path/to/image.png"); var res = this.response; res.writeHead(200, { "content-type": "image/png" }); res.write(f); res.end(); } }); Router.map(function() { Router.route("images", { path: "/images/image.png", where: "server", controller: ImageController
source share