From e0ad2bc49e8f62e8d61edb71eea476e1f1f7c35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20West=C3=B6=C3=B6?= Date: Fri, 23 Jan 2026 21:45:38 +0100 Subject: [PATCH] Fix root path routing - serve index.html for / --- server.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/server.js b/server.js index 128525f..caf0ff1 100644 --- a/server.js +++ b/server.js @@ -47,25 +47,33 @@ app.use(session({ } })); +// Serve static files first +app.use(express.static('public')); + // Middleware to handle routes without .html extension app.use((req, res, next) => { - if (req.path.indexOf('.') === -1 && !req.path.startsWith('/api/') && !req.path.startsWith('/admin/')) { - const file = `${req.path}.html`; - res.sendFile(path.join(__dirname, 'public', file), (err) => { - if (err) next(); - }); - } else if (req.path.indexOf('.') === -1 && req.path.startsWith('/admin/') && req.path !== '/admin/') { - const file = `${req.path}.html`; - res.sendFile(path.join(__dirname, 'public', file), (err) => { - if (err) next(); - }); - } else { - next(); + // Skip API routes + if (req.path.startsWith('/api/')) { + return next(); } -}); -// Serve static files -app.use(express.static('public')); + // Handle root path + if (req.path === '/') { + return res.sendFile(path.join(__dirname, 'public', 'index.html')); + } + + // Handle paths without extensions (not already handled by static middleware) + if (req.path.indexOf('.') === -1) { + const file = `${req.path}.html`; + return res.sendFile(path.join(__dirname, 'public', file), (err) => { + if (err) { + next(); + } + }); + } + + next(); +}); // Configure multer for file uploads (memory storage for CV uploads) const upload = multer({