freeCodeCamp/server/boot/explorer.js

34 lines
934 B
JavaScript
Raw Normal View History

const createDebugger = require('debug');
const log = createDebugger('fcc:boot:explorer');
module.exports = function mountLoopBackExplorer(app) {
if (process.env.NODE_ENV === 'production') {
return;
}
let explorer;
2015-06-03 00:27:02 +00:00
try {
2015-11-06 00:41:19 +00:00
explorer = require('loopback-component-explorer');
2015-11-04 05:51:16 +00:00
} 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() {
log(
2015-11-06 00:41:19 +00:00
'Run `npm install loopback-component-explorer` to enable ' +
'the LoopBack explorer'
2015-06-03 00:27:02 +00:00
);
});
return;
}
const restApiRoot = app.get('restApiRoot');
const mountPath = '/explorer';
2015-06-03 00:27:02 +00:00
2015-11-06 00:41:19 +00:00
explorer(app, { basePath: restApiRoot, mountPath });
app.once('started', function() {
const baseUrl = app.get('url').replace(/\/$/, '');
2015-11-06 00:41:19 +00:00
log('Browse your REST API at %s%s', baseUrl, mountPath);
2015-06-03 00:27:02 +00:00
});
};