From ab2eb18b863218f4f9111fcebb12158f6772ad05 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Sat, 23 Nov 2013 17:54:47 +0000 Subject: [PATCH] Temporary fix for config loader issue #1521 - Reverting some of the refactor towards including Ghost as a module as it prevented Ghost from loading when no config was available. --- core/server.js | 31 +++++++++++++------------------ index.js | 10 ++++++++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/core/server.js b/core/server.js index 694f62e86e75..367fd9efd74a 100644 --- a/core/server.js +++ b/core/server.js @@ -1,11 +1,9 @@ // If no env is set, default to development // This needs to be above all other require() // modules to ensure config gets right setting. -process.env.NODE_ENV = process.env.NODE_ENV || 'development'; // Module dependencies -var configLoader = require('./config-loader.js'), - express = require('express'), +var express = require('express'), when = require('when'), _ = require('underscore'), semver = require('semver'), @@ -21,8 +19,8 @@ var configLoader = require('./config-loader.js'), // Variables ghost = new Ghost(), - init, - setup; + setup, + init; // If we're in development mode, require "when/console/monitor" // for help in seeing swallowed promise errors. @@ -30,19 +28,6 @@ if (process.env.NODE_ENV === 'development') { require('when/monitor/console'); } -// Initializes the ghost application. -function init(app) { - if (!app) { - app = express(); - } - - configLoader.loadConfig().then(function () { - // The server and its dependencies require a populated config - setup(app); - }).otherwise(errors.logAndThrowError); -} - - // Sets up the express server instance. // Instantiates the ghost singleton, // helpers, routes, middleware, and plugins. @@ -168,4 +153,14 @@ function setup(server) { }); } +// Initializes the ghost application. +function init(app) { + if (!app) { + app = express(); + } + + // The server and its dependencies require a populated config + setup(app); +} + module.exports = init; \ No newline at end of file diff --git a/index.js b/index.js index a59691221d0b..8a4b2e7f0907 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,12 @@ // Orchestrates the loading of Ghost // When run from command line. -var ghost = require('./core/server'); +var configLoader = require('./core/config-loader.js'), + errors = require('./core/server/errorHandling'); -ghost(); \ No newline at end of file +process.env.NODE_ENV = process.env.NODE_ENV || 'development'; + +configLoader.loadConfig().then(function () { + var ghost = require('./core/server'); + ghost(); +}).otherwise(errors.logAndThrowError); \ No newline at end of file