Aurélien Georget bd91a2ef93 Add 'packages/strapi-plugin-settings-manager/' from commit 'cd241c14c6a6239bca279e7accd709ba58e87cc8'
git-subtree-dir: packages/strapi-plugin-settings-manager
git-subtree-mainline: 80aa83d8460c95366547e143c74bf79ea6ae69f8
git-subtree-split: cd241c14c6a6239bca279e7accd709ba58e87cc8
2017-01-15 20:14:40 +01:00

108 lines
2.7 KiB
JavaScript

'use strict';
/**
* Schema general dependencies
*/
// Public node modules
var _ = require('lodash');
var validator = require('validator');
var SchemaServer = function(app) {
var schema = {
serverHost: {
type: 'string',
path: 'config/environments/' + app.currentUpdatedEnvironment + '/server.json',
key: 'host',
resolver: function(rootValue, value, scope, cb) {
return cb(null, _.trim(value));
}
},
serverPort: {
type: ['integer', 'string'],
path: 'config/environments/' + app.currentUpdatedEnvironment + '/server.json',
key: 'port',
resolver: function(rootValue, value, scope, cb) {
if (_.isString(value) && _.isEmpty(value)) {
return cb(null, '');
} else if (value >= 0 && value <= 65535) {
return cb(null, value);
}
return cb('Invalid port number', null);
}
},
frontendHost: {
type: 'string',
path: 'config/environments/' + app.currentUpdatedEnvironment + '/server.json',
key: 'frontendUrl',
resolver: function(rootValue, value, scope, cb) {
if (validator.isURL(value) || _.isEmpty(value)) {
return cb(null, value);
}
return cb('Invalid front-end host URL', null);
}
},
reload: {
type: ['boolean', 'object'],
path: 'config/environments/' + app.currentUpdatedEnvironment + '/server.json',
values: {
object: {
timeout: {
type: 'integer'
},
workers: {
type: 'integer'
}
}
}
},
logger: {
type: 'boolean',
path: 'config/environments/' + app.currentUpdatedEnvironment + '/server.json'
},
parser: {
type: ['boolean', 'object'],
path: 'config/environments/' + app.currentUpdatedEnvironment + '/server.json',
values: {
object: {
encode: {
type: 'string'
},
formLimit: {
type: 'string'
},
jsonLimit: {
type: 'string'
},
strict: {
type: 'boolean'
}
}
},
resolver: function(rootValue, value, scope, cb) {
if (_.isObject(value) && !value.hasOwnProperty('extendTypes')) {
value.extendTypes = {
json: ['application/x-javascript']
};
}
return cb(null, value);
}
},
gzip: {
type: 'boolean',
path: 'config/environments/' + app.currentUpdatedEnvironment + '/server.json'
},
responseTime: {
type: 'boolean',
path: 'config/environments/' + app.currentUpdatedEnvironment + '/server.json'
}
};
return schema;
};
module.exports = SchemaServer;