From a8ce117ff7d367433dc1c5115ced6fca3835699a Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 17 Oct 2012 01:15:33 +0100 Subject: [PATCH] Reverse proxy support --- server/app.js | 16 ++++++++++++++++ server/config.json | 1 + 2 files changed, 17 insertions(+) diff --git a/server/app.js b/server/app.js index 2d42e1f..1f06fc1 100644 --- a/server/app.js +++ b/server/app.js @@ -96,6 +96,22 @@ StaticFileServer.prototype.serve = function (request, response) { request.url = '/'; } + // If a forwarded-for header is found, switch the source address + if (request.headers['x-forwarded-for']) { + // Check we're connecting from a whitelisted proxy + if (!kiwi.config.http_proxies + || kiwi.config.http_proxies.indexOf(request.connection.remoteAddress) < 0) + { + console.log('Unlisted proxy:', request.connection.remoteAddress); + response.writeHead(503); + response.end(); + return; + } + + // We're sent from a whitelisted proxy, replace the hosts + request.connection.remoteAddress = request.headers['x-forwarded-for']; + } + this.file_server.serve(request, response, function (err) { if (err) { response.writeHead(err.status, err.headers); diff --git a/server/config.json b/server/config.json index b59fd1b..39da201 100755 --- a/server/config.json +++ b/server/config.json @@ -25,6 +25,7 @@ "handle_http": true, "public_http": "./../client/", "http_base_path": "/client", + "http_proxies": ["127.0.0.1"], "max_client_conns": 2, -- 2.25.1