Spaces:
Running
Running
Upload index.js
Browse files- server/index.js +37 -25
server/index.js
CHANGED
|
@@ -47,20 +47,48 @@ app.use(express.json());
|
|
| 47 |
// Serve static files from the client build in production
|
| 48 |
if (process.env.NODE_ENV === 'production') {
|
| 49 |
app.use(express.static('/usr/share/nginx/html'));
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
app.get('/', (req, res) => {
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
res.json({
|
| 58 |
message: 'BioNexus Hub API',
|
| 59 |
version: '1.0.0',
|
| 60 |
timestamp: new Date().toISOString()
|
| 61 |
});
|
| 62 |
-
}
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
app.get('/api/news', async (req, res) => {
|
| 66 |
try {
|
|
@@ -106,22 +134,6 @@ app.get('/api/datasets/:id', async (req, res) => {
|
|
| 106 |
}
|
| 107 |
});
|
| 108 |
|
| 109 |
-
// Health check endpoint for containerized environments
|
| 110 |
-
app.get('/health', (req, res) => {
|
| 111 |
-
res.status(200).json({
|
| 112 |
-
status: 'OK',
|
| 113 |
-
timestamp: new Date().toISOString(),
|
| 114 |
-
uptime: process.uptime()
|
| 115 |
-
});
|
| 116 |
-
});
|
| 117 |
-
|
| 118 |
-
// In production, serve the React app for any non-API routes
|
| 119 |
-
if (process.env.NODE_ENV === 'production') {
|
| 120 |
-
app.get('*', (req, res) => {
|
| 121 |
-
res.sendFile('/usr/share/nginx/html/index.html');
|
| 122 |
-
});
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
app.listen(PORT, '0.0.0.0', () => {
|
| 126 |
console.log(`BioNexus Hub server running on port ${PORT}`);
|
| 127 |
});
|
|
|
|
| 47 |
// Serve static files from the client build in production
|
| 48 |
if (process.env.NODE_ENV === 'production') {
|
| 49 |
app.use(express.static('/usr/share/nginx/html'));
|
| 50 |
+
|
| 51 |
+
// Health check endpoint for containerized environments
|
| 52 |
+
app.get('/health', (req, res) => {
|
| 53 |
+
res.status(200).json({
|
| 54 |
+
status: 'OK',
|
| 55 |
+
timestamp: new Date().toISOString(),
|
| 56 |
+
uptime: process.uptime()
|
| 57 |
+
});
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
// Serve the React app for the root route
|
| 61 |
+
app.get('/', (req, res) => {
|
| 62 |
+
res.sendFile(path.resolve('/usr/share/nginx/html/index.html'));
|
| 63 |
+
});
|
| 64 |
+
|
| 65 |
+
// In production, serve the React app for any non-API routes
|
| 66 |
+
app.get('*', (req, res) => {
|
| 67 |
+
if (!req.path.startsWith('/api/')) {
|
| 68 |
+
res.sendFile(path.resolve('/usr/share/nginx/html/index.html'));
|
| 69 |
+
} else {
|
| 70 |
+
res.status(404).json({ error: 'API endpoint not found' });
|
| 71 |
+
}
|
| 72 |
+
});
|
| 73 |
+
} else {
|
| 74 |
+
// Development endpoints
|
| 75 |
+
app.get('/', (req, res) => {
|
| 76 |
res.json({
|
| 77 |
message: 'BioNexus Hub API',
|
| 78 |
version: '1.0.0',
|
| 79 |
timestamp: new Date().toISOString()
|
| 80 |
});
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
// Health check endpoint for development
|
| 84 |
+
app.get('/health', (req, res) => {
|
| 85 |
+
res.status(200).json({
|
| 86 |
+
status: 'OK',
|
| 87 |
+
timestamp: new Date().toISOString(),
|
| 88 |
+
uptime: process.uptime()
|
| 89 |
+
});
|
| 90 |
+
});
|
| 91 |
+
}
|
| 92 |
|
| 93 |
app.get('/api/news', async (req, res) => {
|
| 94 |
try {
|
|
|
|
| 134 |
}
|
| 135 |
});
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
app.listen(PORT, '0.0.0.0', () => {
|
| 138 |
console.log(`BioNexus Hub server running on port ${PORT}`);
|
| 139 |
});
|