diff --git a/node/server.js b/node/server.js index e683f7655..731f6b63b 100644 --- a/node/server.js +++ b/node/server.js @@ -19,6 +19,7 @@ var http = require('http') , fs = require('fs') , io = require('socket.io') , sys = require('sys') + , settings = require('./settings') , server; server = http.createServer(function(req, res){ @@ -56,7 +57,7 @@ server = http.createServer(function(req, res){ send404(res, path); } }); -server.listen(9001); +server.listen(settings.port); console.log("Server is listening at port 9001"); function randomPadName() { diff --git a/node/settings.js b/node/settings.js new file mode 100644 index 000000000..49564d257 --- /dev/null +++ b/node/settings.js @@ -0,0 +1,43 @@ +var fs = require("fs"); + +//default settings +exports.port = 9001; + +//read the settings sync +var settingsStr = fs.readFileSync("../settings.json"); + +//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"); + console.error("We recommend http://jsonlint.com/ to find the mistake"); + console.error(e.stack); + 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.error("WARNING: Settings should start with a low character: '" + i + "'"); + } + + //we know this setting, so we overwrite it + if(exports[i]) + { + exports[i] = settings[i]; + } + //this setting is unkown, output a warning and throw it away + else + { + console.error("WARNING: Unkown Setting: '" + i + "'"); + console.error("If this isn't a mistake, add the default settings for this value to node/settings.js"); + } +} diff --git a/settings.json b/settings.json new file mode 100644 index 000000000..3d7f6e2ee --- /dev/null +++ b/settings.json @@ -0,0 +1,3 @@ +{ + "port":9001 +}