0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/core/server/api/configuration.js
Hannah Wolfe 2aff9ed8eb Force apps flag to be boolean in config API
ref #3969

- it shouldn't be possible to set keys via this flag
2014-09-09 08:40:38 +01:00

69 lines
1.9 KiB
JavaScript

// # Configuration API
// RESTful API for browsing the configuration
var _ = require('lodash'),
config = require('../config'),
errors = require('../errors'),
parsePackageJson = require('../require-tree').parsePackageJson,
Promise = require('bluebird'),
configuration;
function getValidKeys() {
var validKeys = {
'fileStorage': config.fileStorage === false ? false : true,
'apps': config.apps === true ? true : false,
'version': false,
'environment': process.env.NODE_ENV,
'database': config.database.client,
'mail': _.isObject(config.mail) ? config.mail.transport : '',
'blogUrl': config.url
};
return parsePackageJson('package.json').then(function (json) {
validKeys.version = json.version;
return validKeys;
});
}
/**
* ## Configuration API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
*/
configuration = {
/**
* ### Browse
* Fetch all configuration keys
* @returns {Promise(Configurations)}
*/
browse: function browse() {
return getValidKeys().then(function (result) {
return Promise.resolve({ 'configuration': _.map(result, function (value, key) {
return {
key: key,
value: value
};
})});
});
},
/**
* ### Read
*
*/
read: function read(options) {
return getValidKeys().then(function (result) {
if (_.has(result, options.key)) {
return Promise.resolve({ 'configuration': [{
key: options.key,
value: result[options.key]
}]});
} else {
return Promise.reject(new errors.NotFoundError('Invalid key'));
}
});
}
};
module.exports = configuration;