From da042f2dba7310fa6b8f513a3e7e1e2b34cb5498 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 27 Jul 2018 23:10:36 -0600 Subject: [PATCH] handle 'none' better --- bin/telebitd.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/bin/telebitd.js b/bin/telebitd.js index d777c85..2bf0237 100755 --- a/bin/telebitd.js +++ b/bin/telebitd.js @@ -143,19 +143,46 @@ controllers.http = function (req, res, opts) { }); } - if ('none' === portOrPath) { + if ('none' === portOrPath || 'none' === subdomain) { + // ~/telebit http none // turn off all + // ~/telebit http none none // (same as above) + // ~/telebit http 3000 none // turn off this handler + // ~/telebit http none sub.example.com // turn off this subdomain + // ~/telebit http none sub // TODO + Object.keys(state.servernames).forEach(function (key) { + if ('none' === portOrPath && 'none' === subdomain) { + delete state.servernames[key].handler; + return; + } + if (state.servernames[key].handler === portOrPath) { + delete state.servernames[key].handler; + return; + } + if (!subdomain || key === subdomain) { + if (state.servernames[key].sub) { + delete state.servernames[key]; + } else { + delete state.servernames[key].handler; + } + return; + } + }); delete state.servernames[subdomain]; remoteHost = 'none'; - } else if (subdomain) { + } else if (subdomain && 'none' !== subdomain) { // use a subdomain with this handler var handlerName = getServername(state.servernames, subdomain); if (!handlerName) { active = false; } if (!state.servernames[subdomain]) { - state.servernames[subdomain] = {}; + state.servernames[subdomain] = { sub: true }; + } + if ('none' === portOrPath) { + delete state.servernames[subdomain].handler; + } else { + state.servernames[subdomain].handler = portOrPath; } - state.servernames[subdomain].handler = portOrPath; remoteHost = subdomain; } else { // just replace the default domain @@ -171,7 +198,7 @@ controllers.http = function (req, res, opts) { //var prefix = appname + '.' + key; var prefix = key; if (!state.servernames[prefix]) { - state.servernames[prefix] = {}; + state.servernames[prefix] = { sub: undefined }; } state.servernames[prefix].handler = portOrPath; remoteHost = prefix; @@ -418,7 +445,7 @@ function serveControlsHelper() { if (conf._servernames) { (conf._servernames||'').split(/,/g).forEach(function (key) { if (!state.config.servernames[key]) { - state.config.servernames[key] = {}; + state.config.servernames[key] = { sub: undefined }; } }); }