Skip to content

Commit 3d616dc

Browse files
authored
Merge pull request #419 from timbornemann/codex/investigate-404-errors-in-docker-build
Fix static asset path detection in Express server
2 parents c8bbda9 + a0c7e3d commit 3d616dc

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

server/app.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import express from "express";
2+
import fs from "fs";
23
import path from "path";
34
import { fileURLToPath } from "url";
45
import routers, { frontendController } from "./controllers/index.js";
56

67
const __filename = fileURLToPath(import.meta.url);
78
const __dirname = path.dirname(__filename);
8-
const DIST_DIR = path.join(__dirname, "..", "dist");
9+
const DIST_CANDIDATES = [
10+
path.resolve(__dirname, "..", "dist"),
11+
path.resolve(__dirname, ".."),
12+
];
13+
const DIST_DIR = DIST_CANDIDATES.find((candidate) =>
14+
fs.existsSync(path.join(candidate, "index.html")),
15+
) ?? DIST_CANDIDATES[0];
916

1017
export const app = express();
1118
app.use(express.json());

0 commit comments

Comments
 (0)