feat: Add debug endpoint to check uploads directory
- Add /debug/uploads endpoint to inspect upload directory status - Shows directory path, existence, file count, and sample files - Helps troubleshoot 404 errors for uploaded images - Displays environment variables related to uploads
This commit is contained in:
@@ -44,6 +44,35 @@ app.get('/health', (req, res) => {
|
|||||||
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Debug endpoint to check uploads directory
|
||||||
|
app.get('/debug/uploads', (req, res) => {
|
||||||
|
const fs = require('fs');
|
||||||
|
const uploadDirPath = process.env.UPLOAD_DIR || path.join(process.cwd(), 'uploads');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const exists = fs.existsSync(uploadDirPath);
|
||||||
|
const files = exists ? fs.readdirSync(uploadDirPath) : [];
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
uploadDir: uploadDirPath,
|
||||||
|
exists,
|
||||||
|
fileCount: files.length,
|
||||||
|
files: files.slice(0, 10), // Show first 10 files
|
||||||
|
cwd: process.cwd(),
|
||||||
|
env: {
|
||||||
|
UPLOAD_DIR: process.env.UPLOAD_DIR,
|
||||||
|
NODE_ENV: process.env.NODE_ENV,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
res.status(500).json({
|
||||||
|
error: error.message,
|
||||||
|
uploadDir: uploadDirPath,
|
||||||
|
cwd: process.cwd(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// API Routes
|
// API Routes
|
||||||
app.use('/api/reports', reportRoutes);
|
app.use('/api/reports', reportRoutes);
|
||||||
app.use('/api/events', eventRoutes);
|
app.use('/api/events', eventRoutes);
|
||||||
|
|||||||
Reference in New Issue
Block a user