From 1470eecb99ec1e632617ca399956ad9ab08b75f3 Mon Sep 17 00:00:00 2001 From: Starstrike Date: Thu, 1 May 2025 09:04:12 -0400 Subject: [PATCH] Fix wallpaper path handling --- backend/src/index.ts | 7 +++++-- frontend/src/components/EventDetails.tsx | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index c1eff80..e577f12 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -19,6 +19,9 @@ app.use(express.json()); // Serve static files from the frontend build directory app.use(express.static(path.join(__dirname, '../frontend/build'))); +// Serve uploaded files +app.use('/uploads', express.static(path.join(__dirname, '../uploads'))); + // Database connection let db: any; @@ -114,7 +117,7 @@ app.get('/api/events/:slug', async (req: Request, res: Response) => { app.post('/api/events', upload.single('wallpaper'), async (req: MulterRequest, res: Response) => { try { const { title, description, date, location, needed_items } = req.body; - const wallpaperPath = req.file ? `/uploads/wallpapers/${req.file.filename}` : null; + const wallpaperPath = req.file ? `${req.file.filename}` : null; // Generate a slug from the title const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, '-'); @@ -139,7 +142,7 @@ app.post('/api/events', upload.single('wallpaper'), async (req: MulterRequest, r res.status(201).json({ ...result, slug, - wallpaper: wallpaperPath, + wallpaper: wallpaperPath ? `/uploads/wallpapers/${wallpaperPath}` : null, needed_items: parsedNeededItems }); } catch (error) { diff --git a/frontend/src/components/EventDetails.tsx b/frontend/src/components/EventDetails.tsx index 6675b13..55fd47a 100644 --- a/frontend/src/components/EventDetails.tsx +++ b/frontend/src/components/EventDetails.tsx @@ -96,7 +96,7 @@ const EventDetails: React.FC = () => {