2013-05-24 14:59:59 +00:00
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
|
2013-07-16 17:42:47 +00:00
|
|
|
var loopback = require('../loopback');
|
2013-07-19 19:07:04 +00:00
|
|
|
var RemoteObjects = require('strong-remoting');
|
2013-05-24 14:59:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Export the middleware.
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = rest;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build a temp app for mounting resources.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function rest() {
|
|
|
|
return function (req, res, next) {
|
2013-07-17 21:29:43 +00:00
|
|
|
var app = req.app;
|
|
|
|
var remotes = app.remotes();
|
|
|
|
|
|
|
|
// get all remote objects
|
|
|
|
var objs = app.remoteObjects();
|
|
|
|
|
|
|
|
// export remote objects
|
|
|
|
remotes.exports = objs;
|
|
|
|
|
|
|
|
var handler = remotes.handler('rest');
|
2013-05-24 14:59:59 +00:00
|
|
|
|
|
|
|
if(req.url === '/routes') {
|
|
|
|
res.send(handler.adapter.allRoutes());
|
|
|
|
} else if(req.url === '/models') {
|
2013-07-17 21:29:43 +00:00
|
|
|
return res.send(remotes.toJSON());
|
2013-05-24 14:59:59 +00:00
|
|
|
} else {
|
|
|
|
handler(req, res, next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|