Benny-Tang commited on
Commit
3759562
·
verified ·
1 Parent(s): bc33d05

Create server-fix.js

Browse files
Files changed (1) hide show
  1. server-fix.js +26 -0
server-fix.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import express from 'express';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ const app = express();
9
+ const PORT = process.env.PORT || 7860;
10
+
11
+ // Serve static files from client/dist
12
+ app.use(express.static(path.join(__dirname, 'client/dist')));
13
+
14
+ // Serve API routes
15
+ app.get('/api/health', (req, res) => {
16
+ res.json({ status: 'ok' });
17
+ });
18
+
19
+ // Fallback to index.html for SPA
20
+ app.get('*', (req, res) => {
21
+ res.sendFile(path.join(__dirname, 'client/dist/index.html'));
22
+ });
23
+
24
+ app.listen(PORT, () => {
25
+ console.log(`Server running on http://localhost:${PORT}/` );
26
+ });