etherpad-lite/node/utils/Settings.js

95 lines
2.5 KiB
JavaScript
Raw Normal View History

2011-05-14 18:42:04 +02:00
/**
2011-05-30 16:53:11 +02:00
* The Settings Modul reads the settings out of settings.json and provides
* this information to the other modules
*/
/*
2011-05-14 18:42:04 +02:00
* 2011 Peter 'Pita' Martischka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2011-05-14 18:22:25 +02:00
var fs = require("fs");
/**
* The IP ep-lite should listen to
*/
exports.ip = "0.0.0.0";
2011-05-30 16:53:11 +02:00
/**
* The Port ep-lite should listen to
*/
2011-05-14 18:22:25 +02:00
exports.port = 9001;
2011-05-30 16:53:11 +02:00
/*
* The Type of the database
*/
2011-05-14 19:57:07 +02:00
exports.dbType = "sqlite";
2011-05-30 16:53:11 +02:00
/**
* This setting is passed with dbType to ueberDB to set up the database
*/
2011-05-14 19:57:07 +02:00
exports.dbSettings = { "filename" : "../var/sqlite.db" };
2011-05-30 16:53:11 +02:00
/**
* The default Text of a new pad
*/
exports.defaultPadText = "Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http:\/\/j.mp/ep-lite\n";
2011-05-30 16:53:11 +02:00
/**
* A flag that shows if minification is enabled or not
*/
exports.minify = true;
2011-05-14 18:22:25 +02:00
/**
* The path of the abiword executable
*/
exports.abiword = null;
2011-05-14 18:22:25 +02:00
//read the settings sync
2011-05-19 15:30:08 +02:00
var settingsStr = fs.readFileSync("../settings.json").toString();
//remove all comments
settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
2011-05-14 18:22:25 +02:00
//try to parse the settings
var settings;
try
{
settings = JSON.parse(settingsStr);
}
catch(e)
{
console.error("There is a syntax error in your settings.json file");
2011-05-19 15:30:08 +02:00
console.error(e.message);
2011-05-14 18:22:25 +02:00
process.exit(1);
}
//loop trough the settings
for(var i in settings)
{
//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 + "'");
2011-05-14 18:22:25 +02:00
}
//we know this setting, so we overwrite it
if(exports[i] !== undefined)
2011-05-14 18:22:25 +02:00
{
exports[i] = settings[i];
}
//this setting is unkown, output a warning and throw it away
else
{
console.warn("Unkown Setting: '" + i + "'");
console.warn("This setting doesn't exist or it was removed");
2011-05-14 18:22:25 +02:00
}
}