2013-11-05 19:16:59 +00:00
|
|
|
/*!
|
|
|
|
* Adds dynamically-updated docs as /explorer
|
|
|
|
*/
|
|
|
|
var path = require('path');
|
|
|
|
var loopback = require('loopback');
|
|
|
|
var swagger = require('loopback/node_modules/strong-remoting/ext/swagger');
|
2013-11-29 15:17:59 +00:00
|
|
|
var express = require('loopback/node_modules/express');
|
2013-11-05 19:16:59 +00:00
|
|
|
var STATIC_ROOT = path.join(__dirname, 'public');
|
|
|
|
|
|
|
|
module.exports = explorer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Example usage:
|
|
|
|
*
|
|
|
|
* var explorer = require('loopback-explorer');
|
|
|
|
* app.use('/explorer', explorer(app));
|
|
|
|
*/
|
|
|
|
|
|
|
|
function explorer(loopbackApplication, options) {
|
2013-11-29 15:17:59 +00:00
|
|
|
var options = options || {};
|
2013-11-05 19:16:59 +00:00
|
|
|
var remotes = loopbackApplication.remotes();
|
|
|
|
swagger(remotes, options);
|
2013-11-29 15:17:59 +00:00
|
|
|
|
|
|
|
var app = express();
|
|
|
|
app.get('/config.json', function(req, res) {
|
|
|
|
res.send({
|
|
|
|
discoveryUrl: (options.basePath || '') + '/swagger/resources'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
app.use(loopback.static(STATIC_ROOT));
|
|
|
|
return app;
|
2013-11-05 19:16:59 +00:00
|
|
|
}
|