From 9ebf764fec74386299aef058931e755c1286f4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hiram=20J=2E=20P=C3=A9rez?= Date: Mon, 9 Nov 2015 21:03:30 -0600 Subject: [PATCH] handle sub option on maybe bounce closes #31 FIXME: missing tests --- server.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server.js b/server.js index 528584e..863966f 100644 --- a/server.js +++ b/server.js @@ -36,6 +36,9 @@ var stats = { tunnels: 0 }; +// are we serving from a subdomain? +var sub = false; + function maybe_bounce(req, res, sock, head) { // without a hostname, we won't know who the request is for var hostname = req.headers.host; @@ -44,6 +47,12 @@ function maybe_bounce(req, res, sock, head) { } var subdomain = tldjs.getSubdomain(hostname); + // if we're serving from a subdomain do a proper check + if (sub) { + var subsub = (subdomain || '').split('.'); + subdomain = subsub.length > 1 ? subsub[0] : ''; + } + if (!subdomain) { return false; } @@ -180,6 +189,8 @@ module.exports = function(opt) { opt = opt || {}; var schema = opt.secure ? 'https' : 'http'; + + sub = opt.subĀ || false; var app = express();