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; }