Merge pull request #123 from strongloop/feature/app-get-api-root

Add app.restApiRoot setting
This commit is contained in:
Miroslav Bajtoš 2014-01-07 07:31:38 -08:00
commit 9fd152f08e
2 changed files with 15 additions and 0 deletions

View File

@ -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) {

View File

@ -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'