From 52c49abdd6bd04dbfc36c1cff4d798ea23bbff29 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 29 Apr 2025 18:03:18 -0400 Subject: [PATCH] Add static file serving for frontend build directory --- backend/src/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/src/index.ts b/backend/src/index.ts index 18cac59..ea4a700 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -3,6 +3,7 @@ import cors from 'cors'; import sqlite3 from 'sqlite3'; import { open } from 'sqlite'; import dotenv from 'dotenv'; +import path from 'path'; dotenv.config(); @@ -13,6 +14,9 @@ const port = process.env.PORT || 3000; app.use(cors()); app.use(express.json()); +// Serve static files from the frontend build directory +app.use(express.static(path.join(__dirname, '../frontend/build'))); + // Database connection let db: any; @@ -162,6 +166,11 @@ async function initializeDatabase() { } } +// Handle client-side routing +app.get('*', (req: Request, res: Response) => { + res.sendFile(path.join(__dirname, '../frontend/build/index.html')); +}); + // Start server app.listen(port, async () => { console.log(`Server running on port ${port}`);