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;
|
|
|
|
}
|
2015-06-03 00:27:02 +00:00
|
|
|
var explorer;
|
|
|
|
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() {
|
2015-06-03 00:27:02 +00:00
|
|
|
console.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;
|
|
|
|
}
|
|
|
|
|
2015-06-03 19:26:11 +00:00
|
|
|
var restApiRoot = app.get('restApiRoot');
|
2015-11-06 00:41:19 +00:00
|
|
|
var 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() {
|
|
|
|
var baseUrl = app.get('url').replace(/\/$/, '');
|
2015-11-06 00:41:19 +00:00
|
|
|
|
|
|
|
console.log('Browse your REST API at %s%s', baseUrl, mountPath);
|
2015-06-03 00:27:02 +00:00
|
|
|
});
|
|
|
|
};
|