Ghost/core/server/config/index.js
Hannah Wolfe 73275d760f Move config path.update to config.load
issue #1789

- we can do this step a bit earlier and it aids with neatness
- also means for tests that config.load() is enough to get config & paths initialised
2014-01-02 20:29:49 +00:00

38 lines
1.2 KiB
JavaScript

// General entry point for all configuration data
//
// This file itself is a wrapper for the root level config.js file.
// All other files that need to reference config.js should use this file.
var loader = require('./loader'),
paths = require('./paths'),
theme = require('./theme'),
ghostConfig;
// Returns NODE_ENV config object
function config() {
// @TODO: get rid of require statement.
// This is currently needed for tests to load config file
// successfully. While running application we should never
// have to directly delegate to the config.js file.
return ghostConfig || require(paths().config)[process.env.NODE_ENV];
}
function loadConfig() {
return loader().then(function (config) {
// Cache the config.js object's environment
// object so we can later refer to it.
// Note: this is not the entirety of config.js,
// just the object appropriate for this NODE_ENV
ghostConfig = config;
// can't load theme settings yet as we don't have the API,
// but we can load the paths
return paths.update(config.url);
});
}
config.load = loadConfig;
config.paths = paths;
config.theme = theme;
module.exports = config;