Merge pull request #2851 from ether/plugin-hook-for-settings-earlier
Plugin hook for settings earlierpull/2860/head
commit
01335bcf8d
|
@ -17,3 +17,4 @@ npm-debug.log
|
|||
*.crt
|
||||
*.key
|
||||
bin/etherpad-1.deb
|
||||
credentials.json
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
This file must be valid JSON. But comments are allowed
|
||||
|
||||
Please edit settings.json, not settings.json.template
|
||||
|
||||
To still commit settings without credentials you can
|
||||
store any credential settings in credentials.json
|
||||
*/
|
||||
{
|
||||
// Name your instance!
|
||||
|
|
|
@ -74,16 +74,6 @@ async.waterfall([
|
|||
// Call loadSettings hook
|
||||
hooks.aCallAll("loadSettings", { settings: settings });
|
||||
|
||||
// Call applySettings hook
|
||||
hooks.aCallAll("applySettings", settings, function(err, newSettings){
|
||||
if(!newSettings) return;
|
||||
newSettings.forEach(function (settingsBlob){
|
||||
for (var setting in settingsBlob){
|
||||
settings[setting] = settingsBlob[setting];
|
||||
};
|
||||
});
|
||||
});
|
||||
callback();
|
||||
},
|
||||
|
||||
//initalize the http server
|
||||
|
|
|
@ -255,13 +255,20 @@ exports.reloadSettings = function reloadSettings() {
|
|||
// Discover where the settings file lives
|
||||
var settingsFilename = argv.settings || "settings.json";
|
||||
|
||||
// Discover if a credential file exists
|
||||
var credentialsFilename = argv.credentials || "credentials.json";
|
||||
|
||||
if (path.resolve(settingsFilename)===settingsFilename) {
|
||||
settingsFilename = path.resolve(settingsFilename);
|
||||
} else {
|
||||
settingsFilename = path.resolve(path.join(exports.root, settingsFilename));
|
||||
}
|
||||
|
||||
var settingsStr;
|
||||
if (path.resolve(credentialsFilename)===credentialsFilename) {
|
||||
credentialsFilename = path.resolve(credentialsFilename);
|
||||
}
|
||||
|
||||
var settingsStr, credentialsStr;
|
||||
try{
|
||||
//read the settings sync
|
||||
settingsStr = fs.readFileSync(settingsFilename).toString();
|
||||
|
@ -269,8 +276,16 @@ exports.reloadSettings = function reloadSettings() {
|
|||
console.warn('No settings file found. Continuing using defaults!');
|
||||
}
|
||||
|
||||
try{
|
||||
//read the credentials sync
|
||||
credentialsStr = fs.readFileSync(credentialsFilename).toString();
|
||||
} catch(e){
|
||||
// Doesn't matter if no credentials file found..
|
||||
}
|
||||
|
||||
// try to parse the settings
|
||||
var settings;
|
||||
var credentials;
|
||||
try {
|
||||
if(settingsStr) {
|
||||
settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}");
|
||||
|
@ -281,6 +296,11 @@ exports.reloadSettings = function reloadSettings() {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
if(credentialsStr) {
|
||||
credentialsStr = jsonminify(credentialsStr).replace(",]","]").replace(",}","}");
|
||||
credentials = JSON.parse(credentialsStr);
|
||||
}
|
||||
|
||||
//loop trough the settings
|
||||
for(var i in settings)
|
||||
{
|
||||
|
@ -307,6 +327,32 @@ exports.reloadSettings = function reloadSettings() {
|
|||
}
|
||||
}
|
||||
|
||||
//loop trough the settings
|
||||
for(var i in credentials)
|
||||
{
|
||||
//test if the setting start with a low character
|
||||
if(i.charAt(0).search("[a-z]") !== 0)
|
||||
{
|
||||
console.warn("Settings should start with a low character: '" + i + "'");
|
||||
}
|
||||
|
||||
//we know this setting, so we overwrite it
|
||||
//or it's a settings hash, specific to a plugin
|
||||
if(exports[i] !== undefined || i.indexOf('ep_')==0)
|
||||
{
|
||||
if (_.isObject(credentials[i]) && !_.isArray(credentials[i])) {
|
||||
exports[i] = _.defaults(credentials[i], exports[i]);
|
||||
} else {
|
||||
exports[i] = credentials[i];
|
||||
}
|
||||
}
|
||||
//this setting is unkown, output a warning and throw it away
|
||||
else
|
||||
{
|
||||
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
|
||||
}
|
||||
}
|
||||
|
||||
log4js.configure(exports.logconfig);//Configure the logging appenders
|
||||
log4js.setGlobalLogLevel(exports.loglevel);//set loglevel
|
||||
process.env['DEBUG'] = 'socket.io:' + exports.loglevel; // Used by SocketIO for Debug
|
||||
|
|
Loading…
Reference in New Issue