Permalink
Browse files

Did some code cleanup, turned config into a json file

  • Loading branch information...
1 parent 19158eb commit 042880c20fbc3c05c2a95e212426f03b5c662d4a @Irrelon committed Mar 3, 2016
Showing with 102 additions and 18 deletions.
  1. +78 −0 .gitignore
  2. +0 −4 config.js
  3. +9 −0 config.json
  4. +15 −14 router.js
View
@@ -0,0 +1,78 @@
+### JetBrains template
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
+
+*.iml
+
+## Directory-based project format:
+.idea/
+# if you remove the above rule, at least ignore the following:
+
+# User-specific stuff:
+# .idea/workspace.xml
+# .idea/tasks.xml
+# .idea/dictionaries
+
+# Sensitive or high-churn files:
+# .idea/dataSources.ids
+# .idea/dataSources.xml
+# .idea/sqlDataSources.xml
+# .idea/dynamic.xml
+# .idea/uiDesigner.xml
+
+# Gradle:
+# .idea/gradle.xml
+# .idea/libraries
+
+# Mongo Explorer plugin:
+# .idea/mongoSettings.xml
+
+## File-based project format:
+*.ipr
+*.iws
+
+## Plugin-specific files:
+
+# IntelliJ
+/out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+### Node template
+# Logs
+logs
+*.log
+npm-debug.log*
+
+# Runtime data
+pids
+*.pid
+*.seed
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directory
+# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
+node_modules
+
+# Created by .ignore support plugin (hsz.mobi)
View
@@ -1,4 +0,0 @@
-routerTable = {};
-routerTable['isocity.isogenicengine.com'] = { target:'http://localhost:9000' }
-routerTable['isocity.co.uk'] = { target:'http://localhost:9000' }
-routerTable['www.isocity.co.uk'] = { target:'http://localhost:9000', errorRedirect:'http://www.isogenicengine.com/demo/isocity-maintenance/' }
View
@@ -0,0 +1,9 @@
+{
+ "server": {
+ "port": 80
+ },
+ "routerTable": {
+ "git.irrelon.com": "http://localhost:10200"
+ },
+ "error": "http://www.google.com"
+}
View
@@ -1,41 +1,42 @@
-///////////////////////////////////////////
-// Set the port you want to listen on here
-///////////////////////////////////////////
-var serverPort = 80;
-
////////////////////////////////////////////////////////////////////////////
// Don't modify anything below here unless you know what you are doing :) //
////////////////////////////////////////////////////////////////////////////
-var configFilePath = __dirname + '/config.js';
+var http = require('http'),
+ httpProxy = require('http-proxy'),
+ fs = require('fs'),
+ proxy = httpProxy.createProxyServer({}),
+ routerTable = {},
+ configFilePath,
+ serverPort;
-var http = require('http'), httpProxy = require('http-proxy'), fs = require('fs');
-var proxy = httpProxy.createProxyServer({});
-var routerTable = {}
+configFilePath = __dirname + '/config.json';
var loadConfigData = function (callback) {
- var self = this;
fs.readFile(configFilePath, 'utf8', function (err, data) {
if (err) { console.log('Error reading router config file: ' + err); } else {
- eval(data);
+ data = JSON.parse(data);
+
+ routerTable = data.routerTable;
+
console.log('Router table config data updated successfully.');
}
if (typeof callback == 'function') { callback(); }
});
-}
+};
var configFileEvent = function (curr, prev) {
if (curr.mtime != prev.mtime) {
// The file has been modified so update the router table
console.log('Router table config data has changed, updating...');
loadConfigData();
}
-}
+};
var do404 = function (res) {
res.writeHead(404);
res.write('Nothing to serve from here. Sorry! (Error 404)');
res.end();
-}
+};
var server = http.createServer(function (req, res) {
// Check for an entry in the router table

0 comments on commit 042880c

Please sign in to comment.