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'