Removing proxy test+debugging output
[KiwiIRC.git] / server / configuration.js
index aaf9513757ed294cc2fe0b9078c7da566a71dd77..bc05e6ebd669adb00dda21f3dafa184d86fac109 100644 (file)
@@ -1,17 +1,24 @@
-var fs = require('fs');
+var fs      = require('fs'),
+    events  = require('events'),
+    util    = require('util');
 
 var config_filename = 'config.js',
     config_dirs = ['/etc/kiwiirc/', __dirname + '/../'],
     environment = 'production',
     loaded_config = Object.create(null);
 
+var Config = function () {
+    events.EventEmitter.call(this);
+};
+util.inherits(Config, events.EventEmitter);
 
-function loadConfig() {
+Config.prototype.loadConfig = function () {
     var new_config,
-        conf_filepath;
+        conf_filepath,
+        i;
 
     // Loop through the possible config paths and find a usable one
-    for (var i in config_dirs) {
+    for (i = 0; i < config_dirs.length; i++) {
         conf_filepath = config_dirs[i] + config_filename;
 
         try {
@@ -37,23 +44,25 @@ function loadConfig() {
 
     if (new_config) {
         loaded_config = new_config;
+        global.config = new_config[environment] || {};
+        this.emit('loaded');
         return loaded_config;
     } else {
         return false;
     }
-}
+};
 
 
 
-module.exports.setEnvironment = function (new_environment) {
+Config.prototype.setEnvironment = function (new_environment) {
     environment = new_environment;
 };
 
 // Get the current config. Optionally for a different environment than currently set
-module.exports.get = function (specific_environment) {
+Config.prototype.get = function (specific_environment) {
     specific_environment = specific_environment || environment;
     
-    return loaded_config[specific_environment];
+    return loaded_config[specific_environment] || {};
 };
 
-module.exports.loadConfig = loadConfig;
\ No newline at end of file
+module.exports = new Config();