From b02527349d90e668c5185f90a5def113bd842fa3 Mon Sep 17 00:00:00 2001 From: Daniel Karnutsch Date: Wed, 4 Dec 2024 13:06:26 +0100 Subject: [PATCH] Use consistent root for serving admin --- admin/server/{server.js => index.js} | 6 +++--- admin/server/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename admin/server/{server.js => index.js} (93%) diff --git a/admin/server/server.js b/admin/server/index.js similarity index 93% rename from admin/server/server.js rename to admin/server/index.js index 18e1644ce..078022de5 100644 --- a/admin/server/server.js +++ b/admin/server/index.js @@ -3,12 +3,12 @@ const express = require("express"); const compression = require("compression"); const helmet = require("helmet"); const fs = require("fs"); +const path = require("path"); const app = express(); const port = process.env.APP_PORT ?? 3000; -// Read index.html file -let indexFile = fs.readFileSync("../build/index.html", "utf8"); +let indexFile = fs.readFileSync(path.join(__dirname, "../build/index.html"), "utf8"); // Replace environment variables indexFile = indexFile.replace(/\$([A-Z_]+)/g, (match, p1) => { @@ -42,7 +42,7 @@ app.get("/status/health", (req, res) => { }); app.use( - express.static("../build", { + express.static(path.join(__dirname, "../build"), { index: false, // Don't send index.html for requests to "/" as it will be handled by the fallback route (with replaced environment variables) setHeaders: (res, path, stat) => { if (path.endsWith(".js")) { diff --git a/admin/server/package.json b/admin/server/package.json index ee737cccf..637f7fae0 100644 --- a/admin/server/package.json +++ b/admin/server/package.json @@ -2,7 +2,7 @@ "name": "server", "private": true, "scripts": { - "serve": "node server.js" + "serve": "node index.js" }, "dependencies": { "compression": "^1.7.5",