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)) {