loopback/lib/middleware/rest.js

42 lines
740 B
JavaScript
Raw Normal View History

2013-05-24 14:59:59 +00:00
/**
* Module dependencies.
*/
var asteroid = require('../asteroid');
var RemoteObjects = require('sl-remoting')
/**
* Export the middleware.
*/
module.exports = rest;
/**
* Build a temp app for mounting resources.
*/
function rest() {
return function (req, res, next) {
var app = req.app;
var remotes = app.remotes();
2013-05-24 22:08:23 +00:00
// get all remote objects
var objs = app.remoteObjects();
2013-05-24 14:59:59 +00:00
2013-05-24 22:08:23 +00:00
// export remote objects
remotes.exports = objs;
2013-05-24 14:59:59 +00:00
var handler = remotes.handler('rest');
if(req.url === '/routes') {
res.send(handler.adapter.allRoutes());
} else if(req.url === '/models') {
return res.send(remotes.toJSON());
} else {
handler(req, res, next);
}
}
}