Skip to content

Commit f2b8dda

Browse files
committed
fix 404 handler
1 parent 969fa6b commit f2b8dda

File tree

2 files changed

+67
-26
lines changed

2 files changed

+67
-26
lines changed

index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,23 @@ app.get("/", (_req, res) => {
7070
res.redirect("v1/products");
7171
});
7272

73-
app.get("*", (_req, res) => {
74-
res
75-
.status(404)
76-
.send(
77-
"404, page not found. See <a href='https://github.com/C4illin/systembolaget-data'>https://github.com/C4illin/systembolaget-data</a> for documentation.",
78-
);
73+
// 404 handler - place this after all other routes
74+
app.use((req, res) => {
75+
res
76+
.status(404)
77+
.format({
78+
'text/html': () => {
79+
res.send(
80+
"404, page not found. See <a href='https://github.com/C4illin/systembolaget-data'>https://github.com/C4illin/systembolaget-data</a> for documentation."
81+
);
82+
},
83+
'application/json': () => {
84+
res.json({ error: "404, page not found", docs: "https://github.com/C4illin/systembolaget-data" });
85+
},
86+
default: () => {
87+
res.send("404, page not found");
88+
}
89+
});
7990
});
8091

8192
app.listen(port, () => {

package-lock.json

Lines changed: 50 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)