loopback/lib/middleware/routes.js

33 lines
531 B
JavaScript
Raw Normal View History

2013-04-09 16:02:36 +00:00
/**
* Module dependencies.
*/
var asteroid = require('../asteroid');
/**
* Export the middleware.
*/
2013-04-18 00:43:00 +00:00
module.exports = routes;
2013-04-09 16:02:36 +00:00
/**
* Build a temp app for mounting resources.
*/
2013-04-18 00:43:00 +00:00
function routes() {
2013-04-09 16:02:36 +00:00
return function (req, res, next) {
// xxx - cache the temp app and only build when modules change?
var tempApp = asteroid();
2013-04-18 00:43:00 +00:00
var routes = req.modules.instanceOf('Route');
2013-04-09 16:02:36 +00:00
// mount all resources
2013-04-18 00:43:00 +00:00
routes.forEach(function (r) {
2013-04-09 16:02:36 +00:00
r.mount(tempApp);
});
tempApp.handle(req, res, next);
}
}