Skip to content

Commit

Permalink
Add middleware for grapher redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyi committed Feb 14, 2025
1 parent 9d4d0a7 commit 1324c9f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions functions/grapher/_middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Env } from "../_common/env.js"
import { getRedirectForUrl } from "../_common/redirectTools.js"

export const onRequest: PagesFunction<Env> = async (context) => {
const url = new URL(context.request.url)
console.log("Looking up redirect for", url.pathname)
const redirect = await getRedirectForUrl(context.env, url)
if (redirect) return redirect
return await context.next()
}

0 comments on commit 1324c9f

Please sign in to comment.