freeCodeCamp/server/boot/explorer.js

28 lines
935 B
JavaScript
Raw Normal View History

module.exports = function mountLoopBackExplorer(app) {
2015-06-03 00:27:02 +00:00
var explorer;
try {
explorer = require('loopback-explorer');
} catch(err) {
// Print the message only when the app was started via `app.listen()`.
2015-06-03 00:27:02 +00:00
// Do not print any message when the project is used as a component.
app.once('started', function() {
2015-06-03 00:27:02 +00:00
console.log(
'Run `npm install loopback-explorer` to enable the LoopBack explorer'
);
});
return;
}
var restApiRoot = app.get('restApiRoot');
2015-06-03 00:27:02 +00:00
var explorerApp = explorer(app, { basePath: restApiRoot });
app.use('/explorer', explorerApp);
app.once('started', function() {
var baseUrl = app.get('url').replace(/\/$/, '');
2015-06-03 00:27:02 +00:00
// express 4.x (loopback 2.x) uses `mountpath`
// express 3.x (loopback 1.x) uses `route`
var explorerPath = explorerApp.mountpath || explorerApp.route;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
});
};