From f58678aca6dd7fe095beff21c934d04a8f535856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 7 Jan 2014 17:58:12 +0100 Subject: [PATCH 1/3] Mount REST API at app.get('restApiRoot') --- templates/app.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/app.js b/templates/app.js index f7eff0e9..132106d6 100644 --- a/templates/app.js +++ b/templates/app.js @@ -51,8 +51,7 @@ app.use(loopback.methodOverride()); */ // LoopBack REST interface -var apiPath = '/api'; -app.use(apiPath, loopback.rest()); +app.use(app.get('restApiRoot'), loopback.rest()); // API explorer (if present) var explorerPath = '/explorer'; From b6337e07c8eaca72cefefecb41fb5f1a94984ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 7 Jan 2014 18:01:09 +0100 Subject: [PATCH 2/3] Emit "start" even when the app starts listening --- templates/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/app.js b/templates/app.js index 132106d6..dbf3d1b8 100644 --- a/templates/app.js +++ b/templates/app.js @@ -146,6 +146,7 @@ app.start = function() { ); } console.log('LoopBack server listening @ %s%s', baseUrl, '/'); + app.emit('start'); } ); } From befe22215122fcea4978a3548347c832e9742382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 7 Jan 2014 18:02:15 +0100 Subject: [PATCH 3/3] Simplify integration of loopback-explorer. When loopback-explorer is not installed, the info message is printed directly form the `catch` block. When loopback-explorer was found, we let the module handle any logging via the "start" event. --- templates/app.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/templates/app.js b/templates/app.js index dbf3d1b8..a1fd0320 100644 --- a/templates/app.js +++ b/templates/app.js @@ -54,14 +54,13 @@ app.use(loopback.methodOverride()); app.use(app.get('restApiRoot'), loopback.rest()); // API explorer (if present) -var explorerPath = '/explorer'; -var explorerConfigured = false; try { var explorer = require('loopback-explorer'); - app.use(explorerPath, explorer(app, { basePath: apiPath })); - explorerConfigured = true; + app.use('/explorer', explorer(app)); } catch(e){ - // ignore errors, explorer stays disabled + console.log( + 'Run `npm install loopback-explorer` to enable the LoopBack explorer' + ); } /* @@ -138,13 +137,6 @@ app.start = function() { return require('http').createServer(app).listen(app.get('port'), app.get('host'), function(){ var baseUrl = 'http://' + app.get('host') + ':' + app.get('port'); - if (explorerConfigured) { - console.log('Browse your REST API at %s%s', baseUrl, explorerPath); - } else { - console.log( - 'Run `npm install loopback-explorer` to enable the LoopBack explorer' - ); - } console.log('LoopBack server listening @ %s%s', baseUrl, '/'); app.emit('start'); }