From e509dabf21972ee1866d3b7596470ca352db7656 Mon Sep 17 00:00:00 2001 From: Hage Yaapa Date: Fri, 28 Aug 2015 22:38:05 +0530 Subject: [PATCH] Register loopback-explorer to app This patch registers loopback-explorer to the app object with its options, making its mountPath property available at app.get('loopback-explorer'). --- index.js | 5 +++-- test/explorer.test.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fbe716d..fad26dc 100644 --- a/index.js +++ b/index.js @@ -21,8 +21,9 @@ explorer.routes = routes; */ function explorer(loopbackApplication, options) { - var mountPath = options.mountPath || '/explorer'; - loopbackApplication.use(mountPath, routes(loopbackApplication, options)); + options = _defaults({}, options, { mountPath: '/explorer' }); + loopbackApplication.use(options.mountPath, routes(loopbackApplication, options)); + loopbackApplication.set('loopback-explorer', options); } function routes(loopbackApplication, options) { diff --git a/test/explorer.test.js b/test/explorer.test.js index c3dd9bb..85b4abe 100644 --- a/test/explorer.test.js +++ b/test/explorer.test.js @@ -12,6 +12,11 @@ describe('explorer', function() { describe('with default config', function() { beforeEach(givenLoopBackAppWithExplorer()); + it('should register "loopback-explorer" to the app', function() { + expect(this.app.get('loopback-explorer')) + .to.have.property('mountPath', '/explorer'); + }); + it('should redirect to /explorer/', function(done) { request(this.app) .get('/explorer') @@ -50,6 +55,11 @@ describe('explorer', function() { describe('with custom explorer base', function() { beforeEach(givenLoopBackAppWithExplorer('/swagger')); + it('should register "loopback-explorer" to the app', function() { + expect(this.app.get('loopback-explorer')) + .to.have.property('mountPath', '/swagger'); + }); + it('should serve correct swagger-ui config', function(done) { request(this.app) .get('/swagger/config.json')