From b0a937d8de8887361a793a0af96c6626a414cf28 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Thu, 19 May 2011 14:30:08 +0100 Subject: [PATCH] Allow comments in the settings file --- node/settings.js | 8 +++++--- settings.json | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/node/settings.js b/node/settings.js index 7cee8b6f1..81abd3b0f 100644 --- a/node/settings.js +++ b/node/settings.js @@ -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); } diff --git a/settings.json b/settings.json index 9ba17de66..c8b2b3274 100644 --- a/settings.json +++ b/settings.json @@ -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" + } + */ }