From d44b347d071a05950bd1ab4913c392c75b9c056e Mon Sep 17 00:00:00 2001 From: Emiel Wit Date: Mon, 20 Nov 2023 11:52:21 +0100 Subject: [PATCH] Update server.js to protocol based on hostname --- server.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 4524a81..ad74623 100644 --- a/server.js +++ b/server.js @@ -21,8 +21,12 @@ const serve = (request, response, file) => { response.status(500).send("Internal Error: " + error.code + " ..\n"); } } else { - const hostname = `${request.protocol}://${request.headers.host}`; - console.log({ protocol: request.protocol, host: request.headers.host }); + const protocol = request.headers.host.includes("localhost") + ? request.protocol + : "https"; + + const hostname = `${protocol}://${request.headers.host}`; + console.log({ protocol: protocol, host: request.headers.host }); const json = content .toString() .replaceAll(HOST, hostname)