2018-01-06 19:24:08 +00:00
|
|
|
const createDebugger = require('debug');
|
|
|
|
|
|
|
|
const log = createDebugger('fcc:boot:explorer');
|
|
|
|
|
2015-06-03 19:26:11 +00:00
|
|
|
module.exports = function mountLoopBackExplorer(app) {
|
2015-06-09 18:54:45 +00:00
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-06 19:24:08 +00:00
|
|
|
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) {
|
2015-06-03 19:26:11 +00:00
|
|
|
// 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.
|
2015-06-03 19:26:11 +00:00
|
|
|
app.once('started', function() {
|
2018-01-06 19:24:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-01-06 19:24:08 +00:00
|
|
|
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 });
|
2015-06-03 19:26:11 +00:00
|
|
|
app.once('started', function() {
|
2018-01-06 19:24:08 +00:00
|
|
|
const baseUrl = app.get('url').replace(/\/$/, '');
|
2015-11-06 00:41:19 +00:00
|
|
|
|
2018-01-06 19:24:08 +00:00
|
|
|
log('Browse your REST API at %s%s', baseUrl, mountPath);
|
2015-06-03 00:27:02 +00:00
|
|
|
});
|
|
|
|
};
|