Add enhanced request logging for debugging
Browse files- Log User-Agent to identify health checks vs real requests
- Add specific logging for asset requests and index.html serving
- Help diagnose why assets aren't loading in HF Spaces
crossword-app/backend/src/app.js
CHANGED
|
@@ -53,7 +53,7 @@ app.use(express.json({ limit: '10mb' }));
|
|
| 53 |
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
|
| 54 |
|
| 55 |
app.use((req, res, next) => {
|
| 56 |
-
console.log(`${new Date().toISOString()} - ${req.method} ${req.path}`);
|
| 57 |
next();
|
| 58 |
});
|
| 59 |
|
|
@@ -76,8 +76,15 @@ if (process.env.NODE_ENV === 'production') {
|
|
| 76 |
|
| 77 |
app.use(express.static(staticPath));
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
// Handle React Router routes - serve index.html for non-API routes
|
| 80 |
app.get('*', (req, res) => {
|
|
|
|
| 81 |
res.sendFile(path.join(staticPath, 'index.html'));
|
| 82 |
});
|
| 83 |
} else {
|
|
|
|
| 53 |
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
|
| 54 |
|
| 55 |
app.use((req, res, next) => {
|
| 56 |
+
console.log(`${new Date().toISOString()} - ${req.method} ${req.path} - User-Agent: ${req.get('User-Agent')?.substring(0, 50) || 'unknown'}`);
|
| 57 |
next();
|
| 58 |
});
|
| 59 |
|
|
|
|
| 76 |
|
| 77 |
app.use(express.static(staticPath));
|
| 78 |
|
| 79 |
+
// Log static file requests specifically
|
| 80 |
+
app.use('/assets/*', (req, res, next) => {
|
| 81 |
+
console.log(`Asset request: ${req.path}`);
|
| 82 |
+
next();
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
// Handle React Router routes - serve index.html for non-API routes
|
| 86 |
app.get('*', (req, res) => {
|
| 87 |
+
console.log(`Serving index.html for: ${req.path}`);
|
| 88 |
res.sendFile(path.join(staticPath, 'index.html'));
|
| 89 |
});
|
| 90 |
} else {
|