From 9561339cf5dfd456a908913f2f6efdfc255ea9cb Mon Sep 17 00:00:00 2001 From: robot Date: Sat, 8 Aug 2026 20:25:29 +0000 Subject: [PATCH] fix(ssr): resolve index.html from production path for CSR shell The CSR shell path was hardcoded to a local dev directory (app/server/browser/index.html) which does not exist in the Docker container. Browser files are copied to /usr/share/nginx/html by the Dockerfile. browserIndexPath() now checks both production and development paths, falling back to the first that exists. --- server.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/server.ts b/server.ts index 9cbefdc..19fc4d2 100644 --- a/server.ts +++ b/server.ts @@ -25,12 +25,35 @@ const appEngine = new AngularNodeAppEngine(); /** * Resolve the static browser index.html path. - * In the built output the browser files live in the `browser/` subdirectory. + * + * Production (Docker): browser files are copied to /usr/share/nginx/html/ + * Local dev (ng build): browser files live in dist/radio-station/browser/ + * Try each candidate in order and return the first that exists. */ function browserIndexPath(): string { - // __dirname in ESM resolves to this file's directory + // Production path — Dockerfile copies browser output here + const productionPaths = [ + '/usr/share/nginx/html/index.html', + '/var/www/html/index.html', + ]; + + // Local dev path — relative to the compiled server directory const dir = typeof __dirname !== 'undefined' ? __dirname : path.dirname(new URL(import.meta.url).pathname); - return path.join(dir, 'browser', 'index.html'); + const localPaths = [ + path.join(dir, 'browser', 'index.html'), + path.join(dir, '..', 'browser', 'index.html'), + ]; + + const allCandidates = [...productionPaths, ...localPaths]; + for (const candidate of allCandidates) { + try { + if (fs.existsSync(candidate)) return candidate; + } catch { + // ignore — keep trying + } + } + // Return the first candidate so the error path has a sensible value to log + return allCandidates[0]; } /**