Add detailed static file debugging
Browse files- Check assets directory contents specifically
- Add /test-static route to debug file serving
- Investigate why browser isn't loading CSS/JS assets
crossword-app/backend/src/app.js
CHANGED
@@ -70,12 +70,33 @@ if (process.env.NODE_ENV === 'production') {
|
|
70 |
try {
|
71 |
const files = fs.readdirSync(staticPath);
|
72 |
console.log(`Static files found:`, files);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
} catch (error) {
|
74 |
console.error(`Error reading static files directory:`, error.message);
|
75 |
}
|
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}`);
|
|
|
70 |
try {
|
71 |
const files = fs.readdirSync(staticPath);
|
72 |
console.log(`Static files found:`, files);
|
73 |
+
|
74 |
+
// Check assets directory specifically
|
75 |
+
const assetsPath = path.join(staticPath, 'assets');
|
76 |
+
if (fs.existsSync(assetsPath)) {
|
77 |
+
const assetFiles = fs.readdirSync(assetsPath);
|
78 |
+
console.log(`Assets directory contents:`, assetFiles);
|
79 |
+
} else {
|
80 |
+
console.error(`Assets directory not found at: ${assetsPath}`);
|
81 |
+
}
|
82 |
} catch (error) {
|
83 |
console.error(`Error reading static files directory:`, error.message);
|
84 |
}
|
85 |
|
86 |
app.use(express.static(staticPath));
|
87 |
|
88 |
+
// Test route to check if static serving works
|
89 |
+
app.get('/test-static', (req, res) => {
|
90 |
+
const fs = require('fs');
|
91 |
+
const assetsPath = path.join(staticPath, 'assets');
|
92 |
+
try {
|
93 |
+
const files = fs.readdirSync(assetsPath);
|
94 |
+
res.json({ staticPath, assetsPath, files });
|
95 |
+
} catch (error) {
|
96 |
+
res.status(500).json({ error: error.message, staticPath, assetsPath });
|
97 |
+
}
|
98 |
+
});
|
99 |
+
|
100 |
// Log static file requests specifically
|
101 |
app.use('/assets/*', (req, res, next) => {
|
102 |
console.log(`Asset request: ${req.path}`);
|