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}`);