From 42dc8b4a8f7199dc37a3e43ab0c6ff69c8d965f2 Mon Sep 17 00:00:00 2001 From: rektide Date: Wed, 16 Oct 2013 02:38:30 -0400 Subject: [PATCH] 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 --- core/server/config/loader.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/server/config/loader.js b/core/server/config/loader.js index 47f87ea038..9b3d250a27 100644 --- a/core/server/config/loader.js +++ b/core/server/config/loader.js @@ -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(); }