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.
This commit is contained in:
parent
6ea8ad20fd
commit
92896a441c
|
@ -241,6 +241,11 @@ app.boot = function(options) {
|
||||||
app.get('port') ||
|
app.get('port') ||
|
||||||
3000;
|
3000;
|
||||||
|
|
||||||
|
appConfig.restApiRoot =
|
||||||
|
appConfig.restApiRoot ||
|
||||||
|
app.get('restApiRoot') ||
|
||||||
|
'/api';
|
||||||
|
|
||||||
if(appConfig.host !== undefined) {
|
if(appConfig.host !== undefined) {
|
||||||
assert(typeof appConfig.host === 'string', 'app.host must be a string');
|
assert(typeof appConfig.host === 'string', 'app.host must be a string');
|
||||||
app.set('host', appConfig.host);
|
app.set('host', appConfig.host);
|
||||||
|
@ -252,6 +257,11 @@ app.boot = function(options) {
|
||||||
app.set('port', appConfig.port);
|
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) {
|
for(var configKey in appConfig) {
|
||||||
var cur = app.get(configKey);
|
var cur = app.get(configKey);
|
||||||
if(cur === undefined || cur === null) {
|
if(cur === undefined || cur === null) {
|
||||||
|
|
|
@ -44,6 +44,7 @@ describe('app', function() {
|
||||||
app: {
|
app: {
|
||||||
port: 3000,
|
port: 3000,
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
|
restApiRoot: '/rest-api',
|
||||||
foo: {bar: 'bat'},
|
foo: {bar: 'bat'},
|
||||||
baz: true
|
baz: true
|
||||||
},
|
},
|
||||||
|
@ -71,6 +72,10 @@ describe('app', function() {
|
||||||
assert.equal(this.app.get('host'), '127.0.0.1');
|
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 () {
|
it('should have other settings', function () {
|
||||||
expect(this.app.get('foo')).to.eql({
|
expect(this.app.get('foo')).to.eql({
|
||||||
bar: 'bat'
|
bar: 'bat'
|
||||||
|
|
Loading…
Reference in New Issue