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