From 7d3e8fa8a950da96c51a174490cbace53f40e011 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Tue, 13 Sep 2016 17:20:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=20=F0=9F=94=A6=20=20add=20nconf=20?= =?UTF-8?q?files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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] --- core/server/config/defaults.json | 35 ++++++++++ .../server/config/env/config.development.json | 12 ++++ core/server/config/env/config.production.json | 12 ++++ .../config/env/config.testing-mysql.json | 17 +++++ core/server/config/env/config.testing-pg.json | 17 +++++ core/server/config/env/config.testing.json | 13 ++++ core/server/config/index.js | 32 +++++++++ core/server/config/overrides.json | 69 +++++++++++++++++++ core/server/config/utils.js | 37 ++++++++++ 9 files changed, 244 insertions(+) create mode 100644 core/server/config/defaults.json create mode 100644 core/server/config/env/config.development.json create mode 100644 core/server/config/env/config.production.json create mode 100644 core/server/config/env/config.testing-mysql.json create mode 100644 core/server/config/env/config.testing-pg.json create mode 100644 core/server/config/env/config.testing.json create mode 100644 core/server/config/index.js create mode 100644 core/server/config/overrides.json create mode 100644 core/server/config/utils.js diff --git a/core/server/config/defaults.json b/core/server/config/defaults.json new file mode 100644 index 000000000000..801b375474d7 --- /dev/null +++ b/core/server/config/defaults.json @@ -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" + } +} diff --git a/core/server/config/env/config.development.json b/core/server/config/env/config.development.json new file mode 100644 index 000000000000..e1f37c33e9a1 --- /dev/null +++ b/core/server/config/env/config.development.json @@ -0,0 +1,12 @@ +{ + "url": "http://localhost:2368", + "database": { + "connection": { + "filename": "content/data/ghost-dev.db" + }, + "debug": false + }, + "paths": { + "contentPath": "content/" + } +} diff --git a/core/server/config/env/config.production.json b/core/server/config/env/config.production.json new file mode 100644 index 000000000000..807bba7cc966 --- /dev/null +++ b/core/server/config/env/config.production.json @@ -0,0 +1,12 @@ +{ + "url": "http://my-ghost-blog.com", + "database": { + "connection": { + "filename": "content/data/ghost.db" + }, + "debug": false + }, + "paths": { + "contentPath": "content/" + } +} diff --git a/core/server/config/env/config.testing-mysql.json b/core/server/config/env/config.testing-mysql.json new file mode 100644 index 000000000000..886d84da557a --- /dev/null +++ b/core/server/config/env/config.testing-mysql.json @@ -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 +} diff --git a/core/server/config/env/config.testing-pg.json b/core/server/config/env/config.testing-pg.json new file mode 100644 index 000000000000..4a63cf62f7ca --- /dev/null +++ b/core/server/config/env/config.testing-pg.json @@ -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 +} diff --git a/core/server/config/env/config.testing.json b/core/server/config/env/config.testing.json new file mode 100644 index 000000000000..14f6ee537c45 --- /dev/null +++ b/core/server/config/env/config.testing.json @@ -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 +} diff --git a/core/server/config/index.js b/core/server/config/index.js new file mode 100644 index 000000000000..b55ae650b3aa --- /dev/null +++ b/core/server/config/index.js @@ -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); diff --git a/core/server/config/overrides.json b/core/server/config/overrides.json new file mode 100644 index 000000000000..1d46aaaa5f30 --- /dev/null +++ b/core/server/config/overrides.json @@ -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 + } +} diff --git a/core/server/config/utils.js b/core/server/config/utils.js new file mode 100644 index 000000000000..6895b5f56b41 --- /dev/null +++ b/core/server/config/utils.js @@ -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)); + } + } + }); +};