From 017d592845ddcfabdd6272dc92d9494c62500a52 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Sun, 28 Sep 2025 11:18:49 -0700 Subject: [PATCH] Feat: Add catch-all redirect handler for slugs --- functions/[slug].js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 functions/[slug].js diff --git a/functions/[slug].js b/functions/[slug].js new file mode 100644 index 0000000..a87aee6 --- /dev/null +++ b/functions/[slug].js @@ -0,0 +1,9 @@ +export async function onRequestGet({ request, params, env }) { + try { + const dest = await env.KV_EV.get(params.slug); + const url = dest ? `https://${dest}` : new URL('/', request.url).href; + return Response.redirect(url, dest ? 301 : 302); + } catch (e) { + return new Response(e.message, { status: 500 }); + } +}