From 4f62cceaa0648188da738d61b8e9787aea50952f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Gro=C3=9F?= Date: Thu, 25 May 2023 09:06:13 +0200 Subject: [PATCH] API: Redirect 404 routes to homepage --- .env.example | 1 + api/jsonApi.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.env.example b/.env.example index 23efe9a..c0a73b7 100644 --- a/.env.example +++ b/.env.example @@ -9,3 +9,4 @@ DB_ROOTPW= DB_PORT= API_PORT=3080 API_ACCESS_TOKEN= +HOMEPAGE_URL= \ No newline at end of file diff --git a/api/jsonApi.js b/api/jsonApi.js index f8351c9..b30235d 100644 --- a/api/jsonApi.js +++ b/api/jsonApi.js @@ -84,6 +84,11 @@ router.get('/most-recent-drop', async (req, res) => { } }); +//Fallback route - Has to be defined last! +router.all('*', (req, res) => { + res.redirect(process.env.HOMEPAGE_URL); +}); + app.use(PREFIX, router); app.use(PREFIX, groupRoutes); app.use(PREFIX, badgeRoutes);