From 70db31bb8fe333d1b42807364ce46bbb05d0e7e9 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 3 Dec 2023 17:03:17 +0000 Subject: [PATCH] Add an index_map which can be used to redirect different hostnames to different app paths so that I can host multiple domains of the same device. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4653 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/core.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/core.js b/core/core.js index 10981c41..3523909b 100644 --- a/core/core.js +++ b/core/core.js @@ -47,6 +47,11 @@ const k_global_settings = { default_value: '/~core/apps/', description: 'Default path.', }, + index_map: { + type: 'textarea', + default_value: undefined, + description: 'Mappings from hostname to redirect path, one per line, as in: "www.tildefriends.net=/~core/index/"', + }, room: { type: 'boolean', default_value: true, @@ -951,6 +956,17 @@ loadSettings().then(function() { httpd.all("", function(request, response) { let match; if (request.uri === "/" || request.uri === "") { + try { + for (let line of (gGlobalSettings.index_map || '').split('\n')) { + let parts = line.split('='); + if (parts.length == 2 && request.headers.host.match(new RegExp(parts[0], 'i'))) { + response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + request.headers.host + parts[1], "Content-Length": "0"}); + return response.end(); + } + } + } catch (e) { + print(e); + } response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + request.headers.host + gGlobalSettings.index, "Content-Length": "0"}); return response.end(); } else if (match = /^(\/~[^\/]+\/[^\/]+)(\/?.*)$/.exec(request.uri)) {