Allow comments in the settings file

This commit is contained in:
Peter 'Pita' Martischka 2011-05-19 14:30:08 +01:00
parent 9849e81e08
commit b0a937d8de
2 changed files with 21 additions and 3 deletions

View File

@ -22,7 +22,10 @@ exports.dbType = "sqlite";
exports.dbSettings = { "filename" : "../var/sqlite.db" };
//read the settings sync
var settingsStr = fs.readFileSync("../settings.json");
var settingsStr = fs.readFileSync("../settings.json").toString();
//remove all comments
settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
//try to parse the settings
var settings;
@ -33,8 +36,7 @@ try
catch(e)
{
console.error("There is a syntax error in your settings.json file");
console.error("We recommend http://jsonlint.com/ to find the mistake");
console.error(e.stack);
console.error(e.message);
process.exit(1);
}

View File

@ -1,7 +1,23 @@
/*
This file must be valid JSON. But comments are allowed
*/
{
"port" : 9001,
//The Type of the database. You can choose between sqlite and mysql
"dbType" : "sqlite",
//the database specific settings
"dbSettings" : {
"filename" : "../var/sqlite.db"
}
/* An Example of MySQL Configuration
"dbType" : "mysql",
"dbSettings" : {
"user" : "root",
"host" : "localhost",
"password": "",
"database": "store"
}
*/
}