From ad733bebc8227e86978f9bddf964fa0f6ebab011 Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Tue, 3 Sep 2024 18:36:05 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20incorporate=20pr=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/_common/grapherRenderer.ts | 2 +- functions/grapher/[slug].ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/functions/_common/grapherRenderer.ts b/functions/_common/grapherRenderer.ts index 1c839036800..8e4e42b9f89 100644 --- a/functions/_common/grapherRenderer.ts +++ b/functions/_common/grapherRenderer.ts @@ -218,7 +218,7 @@ export async function fetchGrapherConfig( const fetchResponse = await fetchUnparsedGrapherConfig(slug, env, etag) if (fetchResponse.status === 404) { - // we throw 404 errors instad of returning a 404 response so that the router + // we throw 404 errors instead of returning a 404 response so that the router // catch handler can do a lookup in the redirects file and maybe send // a 302 redirect response throw new StatusError(404) diff --git a/functions/grapher/[slug].ts b/functions/grapher/[slug].ts index 7390d63abbf..f1a8bfd9a48 100644 --- a/functions/grapher/[slug].ts +++ b/functions/grapher/[slug].ts @@ -51,6 +51,7 @@ export const onRequest: PagesFunction = async (context) => { // so that the common, happy path does not have to fetch the redirects file. if (e instanceof StatusError && e.status === 404) { console.log("Handling 404 for ", url.pathname) + const fullslug = url.pathname.split("/").pop() as string const allExtensions = Object.values(extensions) @@ -64,6 +65,12 @@ export const onRequest: PagesFunction = async (context) => { const slug = matchResult?.groups?.slug ?? fullslug const extension = matchResult?.groups?.extension ?? "" + if (slug.toLowerCase() !== slug) + return createRedirectResponse( + `${slug.toLowerCase()}${extension}`, + url + ) + console.log("Looking up slug and extension", { slug, extension,