E5K7 commited on
Commit
adac7cc
·
1 Parent(s): 0dcd9f7

Fix: Ensure static files are served and NODE_ENV is forced to production on HF

Browse files
Files changed (2) hide show
  1. packages/server/src/index.ts +12 -13
  2. scripts/start-hf.sh +1 -0
packages/server/src/index.ts CHANGED
@@ -39,20 +39,19 @@ app.use('/api/v1', apiRoutes);
39
  // Error handler
40
  app.use(errorHandler);
41
 
42
- // Serve static frontend in production
43
- if (config.NODE_ENV === 'production') {
44
- const __filename = fileURLToPath(import.meta.url);
45
- const __dirname = path.dirname(__filename);
46
-
47
- // In dist/index.js, __dirname is packages/server/dist
48
- // So we go up 3 levels: dist -> server -> packages -> then into client/dist
49
- const clientPath = path.join(__dirname, '../../client/dist');
50
- app.use(express.static(clientPath));
51
-
52
- app.get('*', (req, res) => {
53
- res.sendFile(path.join(clientPath, 'index.html'));
54
  });
55
- }
56
 
57
  // WebSocket
58
  setupWebSocketHandlers(io);
 
39
  // Error handler
40
  app.use(errorHandler);
41
 
42
+ const clientPath = path.join(__dirname, '../../client/dist');
43
+
44
+ // Serve static frontend
45
+ app.use(express.static(clientPath));
46
+
47
+ // Fallback for SPA routing and root
48
+ app.get('*', (req, res) => {
49
+ res.sendFile(path.join(clientPath, 'index.html'), (err) => {
50
+ if (err && !res.headersSent) {
51
+ res.status(404).send('GLMPilot: Frontend build not found. Please ensure npm run build was successful.');
52
+ }
 
53
  });
54
+ });
55
 
56
  // WebSocket
57
  setupWebSocketHandlers(io);
scripts/start-hf.sh CHANGED
@@ -1,4 +1,5 @@
1
  #!/bin/bash
 
2
  # Start Redis in the background with essential flags for containerized environments
3
  echo "Starting Redis server..."
4
  redis-server --daemonize yes --protected-mode no
 
1
  #!/bin/bash
2
+ export NODE_ENV=production
3
  # Start Redis in the background with essential flags for containerized environments
4
  echo "Starting Redis server..."
5
  redis-server --daemonize yes --protected-mode no