fix 404
This commit is contained in:
parent
d4107f8557
commit
1b8477f1cf
10
app.js
10
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}`);
|
||||
|
Loading…
Reference in New Issue
Block a user