From 0d768d73392ddbc2cf5ec19041b9d6225cb80f3b Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Tue, 18 Nov 2025 01:06:12 +0000 Subject: [PATCH] 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 --- server/src/index.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server/src/index.ts b/server/src/index.ts index 76684f7..1fdbea2 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -44,6 +44,35 @@ app.get('/health', (req, res) => { 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 app.use('/api/reports', reportRoutes); app.use('/api/events', eventRoutes);