Skip to content

Commit

Permalink
Merge pull request #117 from Yash-Ainapure/patch4
Browse files Browse the repository at this point in the history
added 404-page
  • Loading branch information
Kritika30032002 authored Dec 18, 2023
2 parents 5381de4 + 198b414 commit d6d2a4b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ app.get("/logout", function (req, res) {
res.redirect("/");
});

// Catch-all route for 404 errors
app.get('*', (req, res) => {
// Redirect to a specific URL or send a custom 404 response

res.status(404).render("404-page");
});

app.listen(process.env.PORT, () => {
mongoose
.connect(process.env.MONGO_SERVER, {
Expand All @@ -224,5 +231,5 @@ app.listen(process.env.PORT, () => {
.catch((error) => {
console.log("DB connection failed", process.env.MONGO_SERVER);
});
console.log(`Server is running on ${process.env.port}`);
console.log(`Server is running on ${process.env.PORT}`);
});
63 changes: 63 additions & 0 deletions views/404-page.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 - Page Not Found</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
.container {
text-align: center;
padding: 20px;
border-radius: 8px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.icon {
font-size: 80px;
color: #f44336;
margin-bottom: 20px;
}
h1 {
color: #333;
margin-bottom: 10px;
}
p {
color: #666;
margin-bottom: 20px;
}
a {
color: #2196F3;
text-decoration: none;
font-weight: bold;
}
</style>
</head>

<body>
<div class="container">
<div class="icon">
<i class="fas fa-exclamation-circle"></i>
</div>
<h1>404 - Page Not Found</h1>
<p>Sorry, the page you are looking for does not exist.</p>
<p><a href="/">Go back to the home page</a></p>
</div>
</body>

</html>

0 comments on commit d6d2a4b

Please sign in to comment.