diff --git a/app/client/src/components/pages/404.js b/app/client/src/components/pages/404.js index 2c00d78f3..db0e8518c 100644 --- a/app/client/src/components/pages/404.js +++ b/app/client/src/components/pages/404.js @@ -4,7 +4,7 @@ import { useEffect } from 'react'; // --- components --- function PageNotFound() { - // redirect to the server side 400.html page + // redirect to the server side 404.html page useEffect(() => { const location = window.location; diff --git a/app/server/app/middleware.js b/app/server/app/middleware.js new file mode 100644 index 000000000..2bd892d10 --- /dev/null +++ b/app/server/app/middleware.js @@ -0,0 +1,31 @@ +const path = require('node:path'); + +function checkClientRouteExists(req, res, next) { + const clientRoutes = [ + '/aquatic-life', + '/community', + '/drinking-water', + '/eating-fish', + '/national', + '/state-and-tribal', + '/swimming', + '/about', + '/data', + '/attains', + '/educators', + '/monitoring-report', + '/plan-summary', + '/waterbody-report', + ].reduce((acc, cur) => { + return acc.concat([`${cur}`, `${cur}/`]); + }, []); + clientRoutes.push('/'); + + if (!clientRoutes.includes(req.path)) { + return res.status(404).sendFile(path.join(__dirname, 'public', '404.html')); + } + + next(); +} + +module.exports = { checkClientRouteExists }; diff --git a/app/server/app/public/400.html b/app/server/app/public/404.html similarity index 94% rename from app/server/app/public/400.html rename to app/server/app/public/404.html index d9300a955..a214b10b3 100644 --- a/app/server/app/public/400.html +++ b/app/server/app/public/404.html @@ -9,8 +9,8 @@ How's My Waterway? | Page Not Found | US EPA - - + + - + @@ -61,7 +61,7 @@ - + - +