From 92896a441c35a3d80b5f6dbd55072f065259628e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 7 Jan 2014 16:05:48 +0100 Subject: [PATCH] Add app.restApiRoot setting Allow loopback users to configure API root via config file, instead of editing app.js generated by loopback-workspace. Allow loopback plugins to discover the path where the REST adapter is mounted. --- lib/application.js | 10 ++++++++++ test/app.test.js | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/lib/application.js b/lib/application.js index a2a0ccfa..76287efd 100644 --- a/lib/application.js +++ b/lib/application.js @@ -241,6 +241,11 @@ app.boot = function(options) { app.get('port') || 3000; + appConfig.restApiRoot = + appConfig.restApiRoot || + app.get('restApiRoot') || + '/api'; + if(appConfig.host !== undefined) { assert(typeof appConfig.host === 'string', 'app.host must be a string'); app.set('host', appConfig.host); @@ -252,6 +257,11 @@ app.boot = function(options) { app.set('port', appConfig.port); } + assert(appConfig.restApiRoot !== undefined, 'app.restBasePath is required'); + assert(typeof appConfig.restApiRoot === 'string', 'app.restBasePath must be a string'); + assert(/^\//.test(appConfig.restApiRoot), 'app.restBasePath must start with "/"'); + app.set('restApiRoot', appConfig.restBasePath); + for(var configKey in appConfig) { var cur = app.get(configKey); if(cur === undefined || cur === null) { diff --git a/test/app.test.js b/test/app.test.js index e472541c..e8bd7df7 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -44,6 +44,7 @@ describe('app', function() { app: { port: 3000, host: '127.0.0.1', + restApiRoot: '/rest-api', foo: {bar: 'bat'}, baz: true }, @@ -71,6 +72,10 @@ describe('app', function() { assert.equal(this.app.get('host'), '127.0.0.1'); }); + it('should have restApiRoot setting', function() { + assert.equal(this.app.get('restApiRoot'), '/rest-api'); + }); + it('should have other settings', function () { expect(this.app.get('foo')).to.eql({ bar: 'bat'