Add static file serving for frontend build directory
This commit is contained in:
@@ -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}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user