0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Accept a config filename as an optional parameter to Ghost start-up.

Closes #1110.
- Promotes config-loader from a validator, to the central place where configuration state is held
- Allow config-loader two means to be told of config file to be used:
  - A preferred first argument passed into Ghost
  - A secondary GHOST_CONFIG environmental variable
- Failing to see either of the above passed in, config-loader will continue to use "config.js"
- Config-loader validates the target configuration (unchanged) & then copies that object into it's own exports
- Components needing to read configuration now require config-loader to retrieve the configuration state
- Config file continues to be loaded via require(): this is assumed to be a static json file
This commit is contained in:
rektide 2013-10-16 02:38:30 -04:00 committed by Hannah Wolfe
parent 7b2bf5b98c
commit 42dc8b4a8f

View file

@ -7,7 +7,7 @@ var fs = require('fs'),
appRoot = paths().appRoot,
configexample = paths().configExample,
config = paths().config;
configFile = process.env.GHOST_CONFIG || paths().config;
function writeConfigFile() {
var written = when.defer();
@ -30,7 +30,7 @@ function writeConfigFile() {
});
read.on('end', written.resolve);
write = fs.createWriteStream(config);
write = fs.createWriteStream(configFile);
write.on('error', function (err) {
/*jslint unparam:true*/
return errors.logError(new Error('Could not open config.js for write.'), appRoot, 'Please check your deployment for config.js or config.example.js.');
@ -50,12 +50,11 @@ function validateConfigEnvironment() {
parsedUrl;
try {
config = require('../../../config')[envVal];
config = require(configFile)[envVal];
} catch (ignore) {
}
// Check if we don't even have a config
if (!config) {
errors.logError(new Error('Cannot find the configuration for the current NODE_ENV'), "NODE_ENV=" + envVal, 'Ensure your config.js has a section for the current NODE_ENV value');
@ -92,7 +91,7 @@ function loadConfig() {
pendingConfig;
/* Check for config file and copy from config.example.js
if one doesn't exist. After that, start the server. */
fs.exists(config, function checkConfig(configExists) {
fs.exists(configFile, function checkConfig(configExists) {
if (!configExists) {
pendingConfig = writeConfigFile();
}