Skip to content

Commit 81d51d4

Browse files
fix: correct static file paths for Docker deployment
- Check both Docker path (/app/public) and local path (../../client/dist) - Use fs.existsSync to determine correct path at startup Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7d95052 commit 81d51d4

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

server/src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ app.use(
5656
app.use(express.json({ limit: '10mb' }));
5757
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
5858

59-
// Serve static files from client/dist in production
59+
// Serve static files in production
60+
// In Docker: /app/public (copied from client build)
61+
// In local prod: ../../client/dist (relative to server/dist)
6062
if (config.nodeEnv === 'production') {
61-
const clientPath = path.join(__dirname, '../../client/dist');
63+
const dockerPath = path.join(__dirname, '../public');
64+
const localPath = path.join(__dirname, '../../client/dist');
65+
const clientPath = require('fs').existsSync(dockerPath) ? dockerPath : localPath;
6266
app.use(express.static(clientPath));
6367
logger.info(`Serving static files from: ${clientPath}`);
6468
}
@@ -73,9 +77,12 @@ app.get('/health', (_req: Request, res: Response) => {
7377

7478
// Serve client app for any other routes in production (SPA routing)
7579
if (config.nodeEnv === 'production') {
76-
app.get('{*path}', (_req: Request, res: Response) => {
77-
const clientPath = path.join(__dirname, '../../client/dist/index.html');
78-
res.sendFile(clientPath);
80+
const dockerIndex = path.join(__dirname, '../public/index.html');
81+
const localIndex = path.join(__dirname, '../../client/dist/index.html');
82+
const indexPath = require('fs').existsSync(dockerIndex) ? dockerIndex : localIndex;
83+
84+
app.get('*', (_req: Request, res: Response) => {
85+
res.sendFile(indexPath);
7986
});
8087
}
8188

0 commit comments

Comments
 (0)