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
This commit is contained in:
parent
1292775a75
commit
70db31bb8f
16
core/core.js
16
core/core.js
@ -47,6 +47,11 @@ const k_global_settings = {
|
|||||||
default_value: '/~core/apps/',
|
default_value: '/~core/apps/',
|
||||||
description: 'Default path.',
|
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: {
|
room: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default_value: true,
|
default_value: true,
|
||||||
@ -951,6 +956,17 @@ loadSettings().then(function() {
|
|||||||
httpd.all("", function(request, response) {
|
httpd.all("", function(request, response) {
|
||||||
let match;
|
let match;
|
||||||
if (request.uri === "/" || request.uri === "") {
|
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"});
|
response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + request.headers.host + gGlobalSettings.index, "Content-Length": "0"});
|
||||||
return response.end();
|
return response.end();
|
||||||
} else if (match = /^(\/~[^\/]+\/[^\/]+)(\/?.*)$/.exec(request.uri)) {
|
} else if (match = /^(\/~[^\/]+\/[^\/]+)(\/?.*)$/.exec(request.uri)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user