mirror of
https://github.com/4ev-link/4ev.link.git
synced 2026-01-13 16:18:05 +00:00
Feat: Add endpoint to get link destination
This commit is contained in:
14
functions/api/links/get.js
Normal file
14
functions/api/links/get.js
Normal file
@@ -0,0 +1,14 @@
|
||||
export async function onRequestGet({ request, env }) {
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const slug = url.searchParams.get('slug');
|
||||
if (!slug) return new Response("Missing slug", { status: 400 });
|
||||
|
||||
const dest = await env.KV_EV.get(slug);
|
||||
if (!dest) return new Response("Link not found", { status: 404 });
|
||||
|
||||
return Response.json({ destination_url: dest });
|
||||
} catch (e) {
|
||||
return new Response(e.message, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user