Merge pull request #92 from strongloop/upgrade-explorer

Upgrade LB Explorer and related changes
This commit is contained in:
Miroslav Bajtoš 2015-10-09 23:26:20 +02:00
commit 517962b4f1
6 changed files with 24 additions and 38 deletions

View File

@ -10,11 +10,9 @@
"errorhandler": "^1.1.1", "errorhandler": "^1.1.1",
"loopback": "^2.0.0", "loopback": "^2.0.0",
"loopback-boot": "^2.0.0", "loopback-boot": "^2.0.0",
"loopback-component-explorer": "^2.1.0",
"loopback-component-storage": "^1.5.0", "loopback-component-storage": "^1.5.0",
"loopback-datasource-juggler": "^2.7.0", "loopback-datasource-juggler": "^2.7.0",
"serve-favicon": "^2.0.1" "serve-favicon": "^2.0.1"
},
"optionalDependencies": {
"loopback-explorer": "^1.1.0"
} }
} }

View File

@ -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);
});
};

View File

@ -1,4 +0,0 @@
module.exports = function mountRestApi(server) {
var restApiRoot = server.get('restApiRoot');
server.use(restApiRoot, server.loopback.rest());
};

View File

@ -0,0 +1,5 @@
{
"loopback-component-explorer": {
"mountPath": "/explorer"
}
}

View File

@ -13,6 +13,9 @@
"parse": { "parse": {
}, },
"routes": { "routes": {
"loopback#rest": {
"paths": ["${restApiRoot}"]
}
}, },
"files": { "files": {
"loopback#static": { "loopback#static": {

View File

@ -3,18 +3,25 @@ var boot = require('loopback-boot');
var app = module.exports = loopback(); var app = module.exports = loopback();
// boot scripts mount components like REST API
boot(app, __dirname);
app.start = function() { app.start = function() {
// start the web server // start the web server
return app.listen(function() { return app.listen(function() {
app.emit('started'); 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` // Bootstrap the application, configure models, datasources and middleware.
if (require.main === module) { // Sub-apps like REST API are mounted via boot scripts.
app.start(); boot(app, __dirname, function(err) {
} if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
app.start();
});