Feat: Add catch-all redirect handler for slugs

This commit is contained in:
2025-09-28 11:18:49 -07:00
parent ce44f5f570
commit 017d592845

9
functions/[slug].js Normal file
View File

@@ -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 });
}
}