Merge pull request #92 from strongloop/upgrade-explorer
Upgrade LB Explorer and related changes
This commit is contained in:
commit
517962b4f1
|
@ -10,11 +10,9 @@
|
|||
"errorhandler": "^1.1.1",
|
||||
"loopback": "^2.0.0",
|
||||
"loopback-boot": "^2.0.0",
|
||||
"loopback-component-explorer": "^2.1.0",
|
||||
"loopback-component-storage": "^1.5.0",
|
||||
"loopback-datasource-juggler": "^2.7.0",
|
||||
"serve-favicon": "^2.0.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"loopback-explorer": "^1.1.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
module.exports = function mountLoopBackExplorer(server) {
|
||||
var explorer;
|
||||
try {
|
||||
explorer = require('loopback-explorer');
|
||||
} catch(err) {
|
||||
console.log(
|
||||
'Run `npm install loopback-explorer` to enable the LoopBack explorer'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
var restApiRoot = server.get('restApiRoot');
|
||||
|
||||
var explorerApp = explorer(server, { basePath: restApiRoot });
|
||||
server.use('/explorer', explorerApp);
|
||||
server.once('started', function() {
|
||||
var baseUrl = server.get('url').replace(/\/$/, '');
|
||||
// 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);
|
||||
});
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
module.exports = function mountRestApi(server) {
|
||||
var restApiRoot = server.get('restApiRoot');
|
||||
server.use(restApiRoot, server.loopback.rest());
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"loopback-component-explorer": {
|
||||
"mountPath": "/explorer"
|
||||
}
|
||||
}
|
|
@ -13,6 +13,9 @@
|
|||
"parse": {
|
||||
},
|
||||
"routes": {
|
||||
"loopback#rest": {
|
||||
"paths": ["${restApiRoot}"]
|
||||
}
|
||||
},
|
||||
"files": {
|
||||
"loopback#static": {
|
||||
|
|
|
@ -3,18 +3,25 @@ var boot = require('loopback-boot');
|
|||
|
||||
var app = module.exports = loopback();
|
||||
|
||||
// boot scripts mount components like REST API
|
||||
boot(app, __dirname);
|
||||
|
||||
app.start = function() {
|
||||
// start the web server
|
||||
return app.listen(function() {
|
||||
app.emit('started');
|
||||
console.log('Web server listening at: %s', app.get('url'));
|
||||
var baseUrl = app.get('url').replace(/\/$/, '');
|
||||
console.log('Web server listening at: %s', baseUrl);
|
||||
if (app.get('loopback-component-explorer')) {
|
||||
var explorerPath = app.get('loopback-component-explorer').mountPath;
|
||||
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// start the server if `$ node server.js`
|
||||
if (require.main === module) {
|
||||
app.start();
|
||||
}
|
||||
// Bootstrap the application, configure models, datasources and middleware.
|
||||
// Sub-apps like REST API are mounted via boot scripts.
|
||||
boot(app, __dirname, function(err) {
|
||||
if (err) throw err;
|
||||
|
||||
// start the server if `$ node server.js`
|
||||
if (require.main === module)
|
||||
app.start();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue