From 2738e61597681f612dc8d5185155ab1b94f73ea8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= <bjorn@dahlgren.at>
Date: Sat, 30 May 2015 02:29:48 +0200
Subject: [PATCH] Use HTTP Basic Auth if username and password is defined in
 config Fixes #5

---
 README.md         | 1 +
 app.js            | 4 ++++
 config.js.example | 4 ++++
 3 files changed, 9 insertions(+)

diff --git a/README.md b/README.md
index 6117751..9340eb6 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,7 @@ path | Folder path to game server
 port | Web port to use
 host | IP or Hostname to listen on
 type | Which kind of server to use, can be 'linux', 'windows' or 'wine'
+auth | If both username and password is set, HTTP Basic Auth will be used
 
 ## How to Use
 
diff --git a/app.js b/app.js
index 858f8dd..8a077df 100644
--- a/app.js
+++ b/app.js
@@ -9,6 +9,10 @@ var app = express();
 var server = require('http').Server(app);
 var io = require('socket.io')(server);
 
+if (config.auth && config.auth.username && config.auth.password) {
+  app.use(express.basicAuth(config.auth.username, config.auth.password));
+}
+
 app.use(express.logger('dev'));
 app.use(express.cookieParser());
 app.use(express.bodyParser());
diff --git a/config.js.example b/config.js.example
index 4ed2b0a..3f5398e 100644
--- a/config.js.example
+++ b/config.js.example
@@ -4,4 +4,8 @@ module.exports = {
   port: 3000,
   host: '0.0.0.0', // Can be either an IP or a Hostname
   type: 'linux', // Can be either linux, windows or wine
+  auth: { // If both username and password is set, HTTP Basic Auth will be used
+    username: '', // Username for HTTP Basic Auth
+    password: '', // Password for HTTP Basic Auth
+  }
 };