3v324v23 commited on
Commit
215bfbe
·
1 Parent(s): 07c8737

Fix HF connectivity: bind to 0.0.0.0 and restore path module

Browse files
Files changed (1) hide show
  1. server/src/index.js +13 -30
server/src/index.js CHANGED
@@ -10,6 +10,7 @@ const rateLimiter = require('./middleware/rateLimiter');
10
  const requestLogger = require('./middleware/requestLogger');
11
  const errorHandler = require('./middleware/errorHandler');
12
  const searchRoutes = require('./routes/search.routes');
 
13
 
14
  const app = express();
15
 
@@ -24,48 +25,30 @@ app.use(cors({
24
  app.use(express.json());
25
  app.use(requestLogger);
26
 
27
- // Root Health Check
28
- app.get('/', (req, res) => {
29
- res.json({
30
- success: true,
31
- message: 'RedThread API Server is active',
32
- version: '1.0.0',
33
- endpoints: {
34
- search: '/api/search',
35
- health: '/api/health'
36
- }
37
- });
38
- });
39
-
40
- const path = require('path');
41
 
42
- // Routes
43
  app.use('/api/search', searchRoutes);
44
  app.use(rateLimiter);
45
-
46
  app.use('/api', routes);
47
 
48
- // Serve Static Files for Deployment
49
- const clientPath = path.join(__dirname, '../../client/out');
50
- app.use(express.static(clientPath));
51
-
52
- // Handle React SPA routing
53
  app.get('*', (req, res, next) => {
54
  if (req.path.startsWith('/api')) return next();
55
  res.sendFile(path.join(clientPath, 'index.html'));
56
  });
57
 
58
- app.use((req, res) => {
59
- res.status(404).json({ success: false, error: 'Route not found' });
60
- });
61
-
62
  app.use(errorHandler);
63
 
64
- app.listen(config.port, () => {
65
- logger.info(`RedThread server running on port ${config.port}`, {
66
- env: config.env,
67
- groqConfigured: !!config.groqApiKey,
68
- endpoints: ['/api/health', '/api/search', '/api/categories', '/api/suggestions'],
 
69
  });
70
  });
71
 
 
10
  const requestLogger = require('./middleware/requestLogger');
11
  const errorHandler = require('./middleware/errorHandler');
12
  const searchRoutes = require('./routes/search.routes');
13
+ const path = require('path');
14
 
15
  const app = express();
16
 
 
25
  app.use(express.json());
26
  app.use(requestLogger);
27
 
28
+ // Serve Static Files for Deployment
29
+ const clientPath = path.join(__dirname, '../../client/out');
30
+ app.use(express.static(clientPath));
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ // API Routes
33
  app.use('/api/search', searchRoutes);
34
  app.use(rateLimiter);
 
35
  app.use('/api', routes);
36
 
37
+ // Handle React SPA routing (Matches everything not caught by API/Statics)
 
 
 
 
38
  app.get('*', (req, res, next) => {
39
  if (req.path.startsWith('/api')) return next();
40
  res.sendFile(path.join(clientPath, 'index.html'));
41
  });
42
 
43
+ // Final Error Handling
 
 
 
44
  app.use(errorHandler);
45
 
46
+ const port = config.port || 7860;
47
+ app.listen(port, '0.0.0.0', () => {
48
+ logger.info(`RedThread server is live at 0.0.0.0:${port}`, {
49
+ mode: config.env,
50
+ clientPath: clientPath,
51
+ groq: !!config.groqApiKey
52
  });
53
  });
54