Files
freeCodeCamp/api-server/server/boot/explorer.js

34 lines
936 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-02 17:27:02 -07:00
try {
2015-11-05 16:41:19 -08:00
explorer = require('loopback-component-explorer');
2015-11-03 21:51:16 -08:00
} catch (err) {
// Print the message only when the app was started via `app.listen()`.
2015-06-02 17:27:02 -07:00
// Do not print any message when the project is used as a component.
app.once('started', function() {
log(
2015-11-05 16:41:19 -08:00
'Run `npm install loopback-component-explorer` to enable ' +
'the LoopBack explorer'
2015-06-02 17:27:02 -07:00
);
});
return;
}
const restApiRoot = app.get('restApiRoot');
const mountPath = '/explorer';
2015-06-02 17:27:02 -07:00
2015-11-05 16:41:19 -08:00
explorer(app, { basePath: restApiRoot, mountPath });
app.once('started', function() {
const baseUrl = app.get('url').replace(/\/$/, '');
2015-11-05 16:41:19 -08:00
log('Browse your REST API at %s%s', baseUrl, mountPath);
2015-06-02 17:27:02 -07:00
});
};