Skip to content

Commit d6d2a4b

Browse files
Merge pull request #117 from Yash-Ainapure/patch4
added 404-page
2 parents 5381de4 + 198b414 commit d6d2a4b

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

app.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ app.get("/logout", function (req, res) {
212212
res.redirect("/");
213213
});
214214

215+
// Catch-all route for 404 errors
216+
app.get('*', (req, res) => {
217+
// Redirect to a specific URL or send a custom 404 response
218+
219+
res.status(404).render("404-page");
220+
});
221+
215222
app.listen(process.env.PORT, () => {
216223
mongoose
217224
.connect(process.env.MONGO_SERVER, {
@@ -224,5 +231,5 @@ app.listen(process.env.PORT, () => {
224231
.catch((error) => {
225232
console.log("DB connection failed", process.env.MONGO_SERVER);
226233
});
227-
console.log(`Server is running on ${process.env.port}`);
234+
console.log(`Server is running on ${process.env.PORT}`);
228235
});

views/404-page.ejs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>404 - Page Not Found</title>
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
9+
<style>
10+
body {
11+
font-family: 'Arial', sans-serif;
12+
background-color: #f5f5f5;
13+
display: flex;
14+
align-items: center;
15+
justify-content: center;
16+
height: 100vh;
17+
margin: 0;
18+
}
19+
20+
.container {
21+
text-align: center;
22+
padding: 20px;
23+
border-radius: 8px;
24+
background-color: #fff;
25+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
26+
}
27+
28+
.icon {
29+
font-size: 80px;
30+
color: #f44336;
31+
margin-bottom: 20px;
32+
}
33+
34+
h1 {
35+
color: #333;
36+
margin-bottom: 10px;
37+
}
38+
39+
p {
40+
color: #666;
41+
margin-bottom: 20px;
42+
}
43+
44+
a {
45+
color: #2196F3;
46+
text-decoration: none;
47+
font-weight: bold;
48+
}
49+
</style>
50+
</head>
51+
52+
<body>
53+
<div class="container">
54+
<div class="icon">
55+
<i class="fas fa-exclamation-circle"></i>
56+
</div>
57+
<h1>404 - Page Not Found</h1>
58+
<p>Sorry, the page you are looking for does not exist.</p>
59+
<p><a href="/">Go back to the home page</a></p>
60+
</div>
61+
</body>
62+
63+
</html>

0 commit comments

Comments
 (0)