gaialive commited on
Commit
a6d0947
·
verified ·
1 Parent(s): 9a42d1f

Upload index.js

Browse files
Files changed (1) hide show
  1. server/index.js +3 -9
server/index.js CHANGED
@@ -11,7 +11,6 @@ dotenv.config();
11
 
12
  const app = express();
13
  // Use port 8501 for Hugging Face Spaces, or 3001 for local development
14
- // Check multiple environment variables that might indicate Hugging Face Spaces
15
  const isHuggingFaceSpaces = process.env.HF_SPACES === 'true' || process.env.HF_SPACES === true || !!process.env.HF_SPACES;
16
  const PORT = isHuggingFaceSpaces ? 8501 : (process.env.PORT || 3001);
17
 
@@ -47,14 +46,9 @@ if (process.env.NODE_ENV === 'development') {
47
 
48
  app.use(express.json());
49
 
50
- // Serve static files from the client build in production
51
  if (process.env.NODE_ENV === 'production') {
52
- app.use(express.static('/usr/share/nginx/html'));
53
-
54
- // Explicitly serve the main index.html file at the root route
55
- app.get('/', (req, res) => {
56
- res.sendFile(path.resolve('/usr/share/nginx/html/index.html'));
57
- });
58
  }
59
 
60
  // Health check endpoint
@@ -130,7 +124,7 @@ if (process.env.NODE_ENV === 'production') {
130
  }
131
 
132
  // Serve the React app for all other routes
133
- res.sendFile(path.resolve('/usr/share/nginx/html/index.html'));
134
  });
135
  } else {
136
  // In development, serve API info at root
 
11
 
12
  const app = express();
13
  // Use port 8501 for Hugging Face Spaces, or 3001 for local development
 
14
  const isHuggingFaceSpaces = process.env.HF_SPACES === 'true' || process.env.HF_SPACES === true || !!process.env.HF_SPACES;
15
  const PORT = isHuggingFaceSpaces ? 8501 : (process.env.PORT || 3001);
16
 
 
46
 
47
  app.use(express.json());
48
 
49
+ // Serve static files from the public directory in production
50
  if (process.env.NODE_ENV === 'production') {
51
+ app.use(express.static(path.join(__dirname, 'public')));
 
 
 
 
 
52
  }
53
 
54
  // Health check endpoint
 
124
  }
125
 
126
  // Serve the React app for all other routes
127
+ res.sendFile(path.resolve(__dirname, 'public', 'index.html'));
128
  });
129
  } else {
130
  // In development, serve API info at root