From 75cb9f7fd2c623a9f45fac44d7228085ba6b469e Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 18 Feb 2024 15:27:44 +0000 Subject: [PATCH] Make things workable with a reverse proxy in front. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4858 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/core.js | 9 +++++---- src/httpd.js.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/core.js b/core/core.js index 085caed7..ea77fea2 100644 --- a/core/core.js +++ b/core/core.js @@ -648,7 +648,7 @@ async function blobHandler(request, response, blobId, uri) { } if (!uri) { - response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + request.headers.host + blobId + '/', "Content-Length": "0"}); + response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + (request.headers['x-forwarded-host'] ?? request.headers.host) + blobId + '/', "Content-Length": "0"}); response.end(); return; } @@ -900,18 +900,19 @@ loadSettings().then(function() { httpd.all("", function default_http_handler(request, response) { let match; if (request.uri === "/" || request.uri === "") { + let host = request.headers['x-forwarded-host'] ?? request.headers.host; 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"}); + if (parts.length == 2 && host.match(new RegExp(parts[0], 'i'))) { + response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + 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://') + host + gGlobalSettings.index, "Content-Length": "0"}); return response.end(); } else if (match = /^(\/~[^\/]+\/[^\/]+)(\/?.*)$/.exec(request.uri)) { return blobHandler(request, response, match[1], match[2]); diff --git a/src/httpd.js.c b/src/httpd.js.c index 6f4933ed..fa136c81 100644 --- a/src/httpd.js.c +++ b/src/httpd.js.c @@ -620,7 +620,7 @@ static void _httpd_endpoint_static_stat(tf_task_t* task, const char* path, int r static void _httpd_endpoint_static(tf_http_request_t* request) { - if (_httpd_redirect(request)) + if (strncmp(request->path, "/.well-known/", strlen("/.well-known/")) && _httpd_redirect(request)) { return; }