Skip to content

Commit

Permalink
Merge pull request #996 from Eastern-Research-Group/feature/775_updat…
Browse files Browse the repository at this point in the history
…e-404-return

Feature/775 update 404 return
  • Loading branch information
maxdiebold-erg authored Aug 23, 2024
2 parents dc6f628 + fdcb1eb commit dd352c7
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 112 deletions.
2 changes: 1 addition & 1 deletion app/client/src/components/pages/404.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
31 changes: 31 additions & 0 deletions app/server/app/middleware.js
Original file line number Diff line number Diff line change
@@ -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 };
92 changes: 44 additions & 48 deletions app/server/app/public/400.html → app/server/app/public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>How&#x27;s My Waterway? | Page Not Found | US EPA</title>

<link rel="canonical" href="https://mywaterway.epa.gov/400.html" />
<link rel="shortlink" href="https://mywaterway.epa.gov/400.html" />
<link rel="canonical" href="https://mywaterway.epa.gov/404.html" />
<link rel="shortlink" href="https://mywaterway.epa.gov/404.html" />
<meta
name="keywords"
content="Clean Water Act (CWA), Safe Drinking Water Act (SDWA), pollution, impaired waterbodies"
Expand All @@ -30,14 +30,14 @@
<meta property="ContentType" content="Basic page" />
<meta property="og:site_name" content="US EPA" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://mywaterway.epa.gov/400.html" />
<meta property="og:url" content="https://mywaterway.epa.gov/404.html" />
<meta
property="og:title"
content="How&#x27;s My Waterway? | Page Not Found | US EPA"
/>
<meta
property="og:image"
content="./epa-template-files/images/epa-standard-og.jpg"
content="/epa-template-files/images/epa-standard-og.jpg"
/>
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
Expand All @@ -61,7 +61,7 @@
<meta name="twitter:image:width" content="1200" />
<meta
name="twitter:image"
content="./epa-template-files/images/epa-standard-twitter.jpg"
content="/epa-template-files/images/epa-standard-twitter.jpg"
/>
<meta
name="description"
Expand All @@ -82,92 +82,88 @@
<link
rel="icon"
type="image/x-icon"
href="./epa-template-files/images/favicon.ico"
href="/epa-template-files/images/favicon.ico"
/>
<meta name="msapplication-TileColor" content="#FFFFFF" />
<meta
name="msapplication-TileImage"
content="./epa-template-files/images/favicon-144.png"
content="/epa-template-files/images/favicon-144.png"
/>
<meta name="application-name" content="US EPA" />
<meta
name="msapplication-config"
content="./epa-template-files/ieconfig.xml"
content="/epa-template-files/ieconfig.xml"
/>
<link rel="manifest" href="./manifest.json" crossorigin="use-credentials" />
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
<link
rel="apple-touch-icon-precomposed"
sizes="196x196"
href="./epa-template-files/images/favicon-196.png"
href="/epa-template-files/images/favicon-196.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="152x152"
href="./epa-template-files/images/favicon-152.png"
href="/epa-template-files/images/favicon-152.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="144x144"
href="./epa-template-files/images/favicon-144.png"
href="/epa-template-files/images/favicon-144.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="120x120"
href="./epa-template-files/images/favicon-120.png"
href="/epa-template-files/images/favicon-120.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="114x114"
href="./epa-template-files/images/favicon-114.png"
href="/epa-template-files/images/favicon-114.png"
/>
<link
rel="apple-touch-icon-precomposed"
sizes="72x72"
href="./epa-template-files/images/favicon-72.png"
href="/epa-template-files/images/favicon-72.png"
/>
<link
rel="apple-touch-icon-precomposed"
href="./epa-template-files/images/favicon-180.png"
href="/epa-template-files/images/favicon-180.png"
/>
<link
rel="icon"
href="./epa-template-files/images/favicon-32.png"
href="/epa-template-files/images/favicon-32.png"
sizes="32x32"
/>
<link
rel="mask-icon"
href="./epa-template-files/images/safari-pinned-tab.svg"
href="/epa-template-files/images/safari-pinned-tab.svg"
color="#ffffff"
/>
<link
rel="preload"
href="./epa-template-files/fonts/source-sans-pro/sourcesanspro-regular-webfont.woff2"
href="/epa-template-files/fonts/source-sans-pro/sourcesanspro-regular-webfont.woff2"
as="font"
crossorigin="anonymous"
/>
<link
rel="preload"
href="./epa-template-files/fonts/source-sans-pro/sourcesanspro-bold-webfont.woff2"
href="/epa-template-files/fonts/source-sans-pro/sourcesanspro-bold-webfont.woff2"
as="font"
crossorigin="anonymous"
/>
<link
rel="preload"
href="./epa-template-files/fonts/source-sans-pro/sourcesanspro-italic-webfont.woff2"
href="/epa-template-files/fonts/source-sans-pro/sourcesanspro-italic-webfont.woff2"
as="font"
crossorigin="anonymous"
/>
<link
rel="preload"
href="./epa-template-files/fonts/merriweather/Latin-Merriweather-Bold.woff2"
href="/epa-template-files/fonts/merriweather/Latin-Merriweather-Bold.woff2"
as="font"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
media="all"
href="./epa-template-files/css/epa.css"
/>
<link rel="stylesheet" media="all" href="/epa-template-files/css/epa.css" />
<!-- Style fixes for the EPA template -->
<style>
[tabindex='-1']:focus {
Expand Down Expand Up @@ -417,7 +413,7 @@
<img
class="usa-banner__header-flag"
aria-hidden="true"
src="./epa-template-files/images/us_flag_small.png"
src="/epa-template-files/images/us_flag_small.png"
alt="U.S. flag"
height="11px"
width="16px"
Expand Down Expand Up @@ -448,7 +444,7 @@
<div class="usa-banner__guidance tablet:grid-col-6">
<img
class="usa-banner__icon usa-media-block__img"
src="./epa-template-files/images/icon-dot-gov.svg"
src="/epa-template-files/images/icon-dot-gov.svg"
alt="Dot gov"
/>
<div class="usa-media-block__body">
Expand All @@ -465,7 +461,7 @@
<div class="usa-banner__guidance tablet:grid-col-6">
<img
class="usa-banner__icon usa-media-block__img"
src="./epa-template-files/images/icon-https.svg"
src="/epa-template-files/images/icon-https.svg"
alt="HTTPS"
/>
<div class="usa-media-block__body">
Expand Down Expand Up @@ -520,15 +516,15 @@
aria-hidden="true"
>
<use
href="./epa-template-files/images/sprite.artifact.svg#magnifying-glass"
href="/epa-template-files/images/sprite.artifact.svg#magnifying-glass"
></use>
</svg>
<svg
class="icon l-header__search-button-icon-close"
aria-hidden="true"
>
<use
href="./epa-template-files/images/sprite.artifact.svg#xmark"
href="/epa-template-files/images/sprite.artifact.svg#xmark"
></use>
</svg>
</button>
Expand Down Expand Up @@ -723,7 +719,7 @@
<button class="button" type="submit" aria-label="Search">
<svg class="icon usa-search__submit-icon" aria-hidden="true">
<use
href="./epa-template-files/images/sprite.artifact.svg#magnifying-glass"
href="/epa-template-files/images/sprite.artifact.svg#magnifying-glass"
></use>
</svg>
<span class="usa-search__submit-text">Search</span>
Expand All @@ -749,7 +745,7 @@
<svg class="icon icon--nav-close" aria-hidden="true" role="img">
<title>Primary navigation</title>
<use
href="./epa-template-files/images/sprite.artifact.svg#xmark"
href="/epa-template-files/images/sprite.artifact.svg#xmark"
></use>
</svg>
</button>
Expand Down Expand Up @@ -816,7 +812,7 @@ <h1 class="page-title" style="font-size: 1.75rem; font-weight: 500">
</h1>
<div class="main-column">
<p style="padding-bottom: 0">
Return to the <a href="./">homepage</a>.
Return to the <a href="/">homepage</a>.
</p>
</div>
</article>
Expand All @@ -828,7 +824,7 @@ <h1 class="page-title" style="font-size: 1.75rem; font-weight: 500">
<div class="l-constrain">
<img
class="footer__epa-seal"
src="./epa-template-files/images/epa-seal.svg"
src="/epa-template-files/images/epa-seal.svg"
alt="United States Environmental Protection Agency"
height="100"
width="100"
Expand Down Expand Up @@ -936,7 +932,7 @@ <h2>Connect.</h2>
<svg class="icon icon--exit is-spaced-before" role="img">
<title>Exit EPA's Website</title>
<use
href="./epa-template-files/images/sprite.svg#launch"
href="/epa-template-files/images/sprite.svg#launch"
></use>
</svg>
</a>
Expand All @@ -956,7 +952,7 @@ <h2>Connect.</h2>
<svg class="icon icon--exit is-spaced-before" role="img">
<title>Exit EPA's Website</title>
<use
href="./epa-template-files/images/sprite.svg#launch"
href="/epa-template-files/images/sprite.svg#launch"
></use>
</svg>
</a>
Expand All @@ -968,7 +964,7 @@ <h2>Connect.</h2>
<svg class="icon icon--exit is-spaced-before" role="img">
<title>Exit EPA's Website</title>
<use
href="./epa-template-files/images/sprite.svg#launch"
href="/epa-template-files/images/sprite.svg#launch"
></use>
</svg>
</a>
Expand Down Expand Up @@ -1028,7 +1024,7 @@ <h2>Follow.</h2>
>
<svg class="icon icon--social" aria-hidden="true">
<use
href="./epa-template-files/images/sprite.artifact.svg#facebook-square"
href="/epa-template-files/images/sprite.artifact.svg#facebook-square"
></use>
</svg>
</a>
Expand All @@ -1041,7 +1037,7 @@ <h2>Follow.</h2>
>
<svg class="icon icon--social" aria-hidden="true">
<use
href="./epa-template-files/images/sprite.artifact.svg#twitter-square"
href="/epa-template-files/images/sprite.artifact.svg#twitter-square"
></use>
</svg>
</a>
Expand All @@ -1054,7 +1050,7 @@ <h2>Follow.</h2>
>
<svg class="icon icon--social" aria-hidden="true">
<use
href="./epa-template-files/images/sprite.artifact.svg#youtube-square"
href="/epa-template-files/images/sprite.artifact.svg#youtube-square"
></use>
</svg>
</a>
Expand All @@ -1067,7 +1063,7 @@ <h2>Follow.</h2>
>
<svg class="icon icon--social" aria-hidden="true">
<use
href="./epa-template-files/images/sprite.artifact.svg#flickr-square"
href="/epa-template-files/images/sprite.artifact.svg#flickr-square"
></use>
</svg>
</a>
Expand All @@ -1080,7 +1076,7 @@ <h2>Follow.</h2>
>
<svg class="icon icon--social" aria-hidden="true">
<use
href="./epa-template-files/images/sprite.artifact.svg#instagram-square"
href="/epa-template-files/images/sprite.artifact.svg#instagram-square"
></use>
</svg>
</a>
Expand All @@ -1093,13 +1089,13 @@ <h2>Follow.</h2>

<a href="#top" class="back-to-top" title="Back to top" aria-hidden="true">
<svg class="back-to-top__icon" aria-hidden="true">
<use href="./epa-template-files/images/sprite.artifact.svg#angle"></use>
<use href="/epa-template-files/images/sprite.artifact.svg#angle"></use>
</svg>
</a>

<script src="./epa-template-files/js/once.min.js"></script>
<script src="./epa-template-files/js/common.min.js"></script>
<script src="./epa-template-files/js/scripts.min.js"></script>
<script src="/epa-template-files/js/once.min.js"></script>
<script src="/epa-template-files/js/common.min.js"></script>
<script src="/epa-template-files/js/scripts.min.js"></script>
<!-- EPA template script mobile drawer fix -->
<script>
const searchButton = document.querySelector(
Expand Down
Loading

0 comments on commit dd352c7

Please sign in to comment.