Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -46,7 +46,9 @@ const port = process.env.PORT || 3000;
|
|
| 46 |
// Middleware
|
| 47 |
app.use(cors());
|
| 48 |
app.use(express.json());
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
|
| 51 |
// Store logs in memory (in production, use a database)
|
| 52 |
let serverLogs = [];
|
|
@@ -256,34 +258,7 @@ app.get('/', (req, res) => {
|
|
| 256 |
userAgent: req.get('User-Agent'),
|
| 257 |
ip: req.ip
|
| 258 |
});
|
| 259 |
-
res.sendFile(path.join(__dirname, '
|
| 260 |
-
});
|
| 261 |
-
|
| 262 |
-
app.get('/status', (req, res) => {
|
| 263 |
-
log('info', 'Status page accessed', {
|
| 264 |
-
path: req.path,
|
| 265 |
-
userAgent: req.get('User-Agent'),
|
| 266 |
-
ip: req.ip
|
| 267 |
-
});
|
| 268 |
-
res.sendFile(path.join(__dirname, 'public', 'status.html'));
|
| 269 |
-
});
|
| 270 |
-
|
| 271 |
-
app.get('/admin', (req, res) => {
|
| 272 |
-
log('info', 'Admin page accessed', {
|
| 273 |
-
path: req.path,
|
| 274 |
-
userAgent: req.get('User-Agent'),
|
| 275 |
-
ip: req.ip
|
| 276 |
-
});
|
| 277 |
-
res.sendFile(path.join(__dirname, 'public', 'admin.html'));
|
| 278 |
-
});
|
| 279 |
-
|
| 280 |
-
app.get('/server-logs', (req, res) => {
|
| 281 |
-
log('info', 'Server logs page accessed', {
|
| 282 |
-
path: req.path,
|
| 283 |
-
userAgent: req.get('User-Agent'),
|
| 284 |
-
ip: req.ip
|
| 285 |
-
});
|
| 286 |
-
res.sendFile(path.join(__dirname, 'public', 'server-logs.html'));
|
| 287 |
});
|
| 288 |
|
| 289 |
// API Routes
|
|
@@ -770,6 +745,27 @@ app.get('/isubmissionopen', (req, res) => {
|
|
| 770 |
});
|
| 771 |
});
|
| 772 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 773 |
// Socket.IO connection handling
|
| 774 |
io.on('connection', (socket) => {
|
| 775 |
log('info', 'Client connected to server logs', {
|
|
|
|
| 46 |
// Middleware
|
| 47 |
app.use(cors());
|
| 48 |
app.use(express.json());
|
| 49 |
+
|
| 50 |
+
// Serve static files from React build directory
|
| 51 |
+
app.use(express.static(path.join(__dirname, 'build')));
|
| 52 |
|
| 53 |
// Store logs in memory (in production, use a database)
|
| 54 |
let serverLogs = [];
|
|
|
|
| 258 |
userAgent: req.get('User-Agent'),
|
| 259 |
ip: req.ip
|
| 260 |
});
|
| 261 |
+
res.sendFile(path.join(__dirname, 'build', 'index.html'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
});
|
| 263 |
|
| 264 |
// API Routes
|
|
|
|
| 745 |
});
|
| 746 |
});
|
| 747 |
|
| 748 |
+
// Catch-all route for React Router - serve index.html for all non-API routes
|
| 749 |
+
app.get('*', (req, res) => {
|
| 750 |
+
// Skip API routes
|
| 751 |
+
if (req.path.startsWith('/api/')) {
|
| 752 |
+
return res.status(404).json({ error: 'API endpoint not found' });
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
// Skip the /isubmissionopen endpoint
|
| 756 |
+
if (req.path === '/isubmissionopen') {
|
| 757 |
+
return res.status(404).json({ error: 'Endpoint not found' });
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
log('info', 'React route accessed', {
|
| 761 |
+
path: req.path,
|
| 762 |
+
userAgent: req.get('User-Agent'),
|
| 763 |
+
ip: req.ip
|
| 764 |
+
});
|
| 765 |
+
|
| 766 |
+
res.sendFile(path.join(__dirname, 'build', 'index.html'));
|
| 767 |
+
});
|
| 768 |
+
|
| 769 |
// Socket.IO connection handling
|
| 770 |
io.on('connection', (socket) => {
|
| 771 |
log('info', 'Client connected to server logs', {
|