2016-09-13 19:35:20 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../../server/config'),
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils = {};
|
|
|
|
|
|
|
|
configUtils.config = config;
|
|
|
|
configUtils.defaultConfig = _.cloneDeep(config.get());
|
|
|
|
|
2016-09-13 19:35:20 +03:00
|
|
|
/**
|
|
|
|
* configUtils.set({});
|
|
|
|
* configUtils.set('key', 'value');
|
|
|
|
*/
|
|
|
|
configUtils.set = function () {
|
|
|
|
var key = arguments[0],
|
|
|
|
value = arguments[1];
|
|
|
|
|
|
|
|
if (_.isObject(key)) {
|
|
|
|
_.each(key, function (value, key) {
|
|
|
|
config.set(key, value);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
config.set(key, value);
|
|
|
|
}
|
2015-12-14 23:05:11 +03:00
|
|
|
};
|
|
|
|
|
2016-09-13 19:35:20 +03:00
|
|
|
/**
|
|
|
|
* important: do not delete cloneDeep for value
|
|
|
|
* nconf keeps this as a reference and then it can happen that the defaultConfig get's overridden by new values
|
|
|
|
*/
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.restore = function () {
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
/**
|
|
|
|
* we have to reset the whole config object
|
|
|
|
* config keys, which get set via a test and do not exist in the config files, won't get reseted
|
|
|
|
*/
|
|
|
|
config.reset();
|
|
|
|
|
2016-09-13 19:35:20 +03:00
|
|
|
_.each(configUtils.defaultConfig, function (value, key) {
|
|
|
|
config.set(key, _.cloneDeep(value));
|
2015-12-14 23:05:11 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = configUtils;
|