Skip to content

Commit

Permalink
🔨 incorporate pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Sep 5, 2024
1 parent 93ddb9f commit 546f675
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion functions/_common/grapherRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions functions/grapher/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 546f675

Please sign in to comment.