Add static file serving for frontend build directory

This commit is contained in:
Your Name
2025-04-29 18:03:18 -04:00
parent ffae4f909a
commit 52c49abdd6

View File

@@ -3,6 +3,7 @@ import cors from 'cors';
import sqlite3 from 'sqlite3'; import sqlite3 from 'sqlite3';
import { open } from 'sqlite'; import { open } from 'sqlite';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import path from 'path';
dotenv.config(); dotenv.config();
@@ -13,6 +14,9 @@ const port = process.env.PORT || 3000;
app.use(cors()); app.use(cors());
app.use(express.json()); app.use(express.json());
// Serve static files from the frontend build directory
app.use(express.static(path.join(__dirname, '../frontend/build')));
// Database connection // Database connection
let db: any; 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 // Start server
app.listen(port, async () => { app.listen(port, async () => {
console.log(`Server running on port ${port}`); console.log(`Server running on port ${port}`);