Vulcan/server/helpers/serve.js

19 lines
718 B
JavaScript
Raw Normal View History

// Very simple function to serve a particular function at a particular URL
// The request's path has to be _exactly_ path.
// Sure, we could make it smarter, but I'm guessing this isn't the way things
// will work long term.
Meteor.serve = function(path, fn) {
2013-04-05 11:58:37 +09:00
var connect = (typeof(Npm) == "undefined") ? __meteor_bootstrap__.require("connect") : Npm.require("connect");
__meteor_bootstrap__.app
.use(connect.query()) // <- XXX: we can probably assume accounts did this
.use(function(req, res, next) {
var test = ('/' + path);
if (req.url.substring(0, test.length) !== test)
return next();
// just run fn() and return it to the requester
res.end(fn(req))
});
}