Skip to content

Commit

Permalink
✨ 🔦 add nconf files
Browse files Browse the repository at this point in the history
refs #6982
- add defaults.json
- add overrides.json
- add env specific default values
- add nconf wrapper in /config
- add config utils in /config/utils.js

[ci skip]
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 20, 2016
1 parent 96203a4 commit 7d3e8fa
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 0 deletions.
35 changes: 35 additions & 0 deletions core/server/config/defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"url": "http://localhost:2368",
"urlSSL": false,
"forceAdminSSL": false,
"server": {
"host": "127.0.0.1",
"port": 2368
},
"database": {
"client": "sqlite3",
"debug": false,
"connection": {
"filename": "content/data/ghost.db"
}
},
"privacy": false,
"paths": {
"contentPath": "content/",
"themePath": "content/themes/",
"imagesPath": "content/images/",
"appPath": "content/apps/",
"storagePath": {
"custom": "content/storage/"
},
"schedulingPath": "core/server/scheduling/"
},
"storage": {
"active": {
"images": "local-file-store"
}
},
"scheduling": {
"active": "SchedulingDefault"
}
}
12 changes: 12 additions & 0 deletions core/server/config/env/config.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"url": "http://localhost:2368",
"database": {
"connection": {
"filename": "content/data/ghost-dev.db"
},
"debug": false
},
"paths": {
"contentPath": "content/"
}
}
12 changes: 12 additions & 0 deletions core/server/config/env/config.production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"url": "http://my-ghost-blog.com",
"database": {
"connection": {
"filename": "content/data/ghost.db"
},
"debug": false
},
"paths": {
"contentPath": "content/"
}
}
17 changes: 17 additions & 0 deletions core/server/config/env/config.testing-mysql.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"url": "http://127.0.0.1:2369",
"server": {
"port": 2369
},
"database": {
"client": "mysql",
"connection": {
"host" : "127.0.0.1",
"user" : "root",
"password" : "",
"database" : "ghost_testing",
"charset" : "utf8"
}
},
"logging": false
}
17 changes: 17 additions & 0 deletions core/server/config/env/config.testing-pg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"url": "http://127.0.0.1:2369",
"server": {
"port": 2369
},
"database": {
"client": "pg",
"connection": {
"host" : "127.0.0.1",
"user" : "postgres",
"password" : "",
"database" : "ghost_testing",
"charset" : "utf8"
}
},
"logging": false
}
13 changes: 13 additions & 0 deletions core/server/config/env/config.testing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"url": "http://127.0.0.1:2369",
"database": {
"connection": {
"filename": "content/data/ghost-test.db"
},
"useNullAsDefault": true
},
"server": {
"port": 2369
},
"logging": false
}
32 changes: 32 additions & 0 deletions core/server/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var nconf = require('nconf'),
path = require('path'),
localUtils = require('./utils'),
env = process.env.NODE_ENV || 'development';

nconf.set('NODE_ENV', env);

/**
* command line arguments
*/
nconf.argv();

/**
* env arguments
*/
nconf.env();

/**
* load config files
*/
nconf.file('1', __dirname + '/overrides.json');
nconf.file('2', path.join(process.cwd(), 'config.' + env + '.json'));
nconf.file('3', __dirname + '/env/config.' + env + '.json');
nconf.file('4', __dirname + '/defaults.json');

/**
* transform all relative paths to absolute paths
*/
localUtils.makePathsAbsolute.bind(nconf)();

module.exports = nconf;
module.exports.isPrivacyDisabled = localUtils.isPrivacyDisabled.bind(nconf);
69 changes: 69 additions & 0 deletions core/server/config/overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"ghostVersion": "0.10.1",
"paths": {
"appRoot": ".",
"corePath": "core/",
"internalAppPath": "core/server/apps/",
"storagePath": {
"default": "core/server/storage/"
},
"clientAssets": "core/built/assets",
"imagesRelPath": "content/images",
"helperTemplates": "core/server/helpers/tpl/",
"adminViews": "core/server/views/"
},
"internalApps": [
"private-blogging",
"subscribers",
"amp"
],
"routeKeywords": {
"tag": "tag",
"author": "author",
"page": "page",
"preview": "p",
"private": "private",
"subscribe": "subscribe",
"amp": "amp"
},
"slugs": {
"reserved": ["admin", "app", "apps", "archive", "archives", "categories",
"category", "dashboard", "feed", "ghost-admin", "login", "logout",
"page", "pages", "post", "posts", "public", "register", "setup",
"signin", "signout", "signup", "user", "users", "wp-admin", "wp-login"],
"protected": ["ghost", "rss", "amp"]
},
"uploads": {
"subscribers": {
"extensions": [".csv"],
"contentTypes": ["text/csv", "application/csv", "application/octet-stream"]
},
"images": {
"extensions": [".jpg", ".jpeg", ".gif", ".png", ".svg", ".svgz"],
"contentTypes": ["image/jpeg", "image/png", "image/gif", "image/svg+xml"]
},
"db": {
"extensions": [".json", ".zip"],
"contentTypes": ["application/octet-stream", "application/json", "application/zip", "application/x-zip-compressed"]
},
"themes": {
"extensions": [".zip"],
"contentTypes": ["application/zip", "application/x-zip-compressed"]
}
},
"storage": {
"active": {
"themes": "local-file-store"
}
},
"times": {
"cannotScheduleAPostBeforeInMinutes": 2,
"publishAPostBySchedulerToleranceInMinutes": 2
},
"theme": {
"timezone": "Etc/UTC"
},
"maintenance": {
"enabled": false
}
}
37 changes: 37 additions & 0 deletions core/server/config/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var path = require('path'),
_ = require('lodash');

exports.isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
if (!this.get('privacy')) {
return false;
}

if (this.get('privacy').useTinfoil === true) {
return true;
}

return this.get('privacy')[privacyFlag] === false;
};

/**
* transform all relative paths to absolute paths
* @TODO: imagesRelPath is a dirty little attribute (especially when looking at the usages)
*/
exports.makePathsAbsolute = function makePathsAbsolute(paths, parent) {
var self = this;

if (!paths && !parent) {
paths = this.get('paths');
parent = 'paths';
}

_.each(paths, function (configValue, pathsKey) {
if (_.isObject(configValue)) {
makePathsAbsolute.bind(self)(configValue, parent + ':' + pathsKey);
} else {
if (configValue[0] !== '/' && pathsKey !== 'imagesRelPath') {
self.set(parent + ':' + pathsKey, path.join(__dirname + '/../../../', configValue));
}
}
});
};

0 comments on commit 7d3e8fa

Please sign in to comment.