diff --git a/app.js b/app.js index be4dcbc..e925847 100644 --- a/app.js +++ b/app.js @@ -147,7 +147,6 @@ app.post('/contact', (req, res) => { }); }); - // Blog Post Route app.get('/blog/:slug', (req, res) => { const slug = req.params.slug; @@ -166,15 +165,18 @@ app.get('/blog/:slug', (req, res) => { blogPosts }); } else { - res.status(404).render('404', { title: 'Post not found' }); + res.redirect('/'); // Redirect to the home page if the blog post is not found } }); -// Request a Quote form remains unchanged +// Global 404 handler for any other unmatched routes +app.use((req, res) => { + res.redirect('/'); // Redirect to the home page for any 404 error +}); + // ================================ // Server Listening // ================================ - const PORT = process.env.PORT || 8899; app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`);