2013-05-24 14:59:59 +00:00
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var asteroid = require('../asteroid');
|
2013-06-05 16:35:35 +00:00
|
|
|
var RemoteObjects = require('sl-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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|