mirror of
https://github.com/4ev-link/4ev.link.git
synced 2026-01-13 16:18:05 +00:00
Feat: Add catch-all redirect handler for slugs
This commit is contained in:
9
functions/[slug].js
Normal file
9
functions/[slug].js
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user