Spaces:
Running
Running
Upload index.js
Browse files- server/index.js +13 -7
server/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const cors = require('cors');
|
| 3 |
const dotenv = require('dotenv');
|
|
|
|
| 4 |
|
| 5 |
// Import models
|
| 6 |
const News = require('./models/News');
|
|
@@ -45,15 +46,20 @@ app.use(express.json());
|
|
| 45 |
|
| 46 |
// Serve static files from the client build in production
|
| 47 |
if (process.env.NODE_ENV === 'production') {
|
| 48 |
-
app.use(express.static('
|
| 49 |
}
|
| 50 |
|
| 51 |
app.get('/', (req, res) => {
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
});
|
| 58 |
|
| 59 |
app.get('/api/news', async (req, res) => {
|
|
@@ -112,7 +118,7 @@ app.get('/health', (req, res) => {
|
|
| 112 |
// In production, serve the React app for any non-API routes
|
| 113 |
if (process.env.NODE_ENV === 'production') {
|
| 114 |
app.get('*', (req, res) => {
|
| 115 |
-
res.sendFile('index.html'
|
| 116 |
});
|
| 117 |
}
|
| 118 |
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const cors = require('cors');
|
| 3 |
const dotenv = require('dotenv');
|
| 4 |
+
const path = require('path');
|
| 5 |
|
| 6 |
// Import models
|
| 7 |
const News = require('./models/News');
|
|
|
|
| 46 |
|
| 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 |
+
if (process.env.NODE_ENV === 'production') {
|
| 54 |
+
// In production, serve the React app
|
| 55 |
+
res.sendFile('/usr/share/nginx/html/index.html');
|
| 56 |
+
} else {
|
| 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) => {
|
|
|
|
| 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 |
|