Skip to content
Prev Previous commit
Next Next commit
Update redirect.ts
  • Loading branch information
samestrin committed May 14, 2024
commit 29d8c94ab59efe876ec56f7df52f0f4be8b7ffba
11 changes: 11 additions & 0 deletions netlify/edge-functions/redirect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import handler from "./utils.ts";
const { fetchFromSupabase, logClick } = handler();

/**
* Handles redirection for shortened URLs and logs the click.
*
* @param request - The incoming request object.
* @returns A response object with a redirection or an error message.
* @throws Throws an error if there is an issue with fetching data from Supabase or logging the click.
*
* @example
* // This function is used as an Edge Function to handle URL redirection.
* // No direct invocation example is provided as it handles HTTP requests.
*/
export default async (request: Request): Promise<Response> => {
try {
const shortUrl = new URL(request.url).pathname.replace("/", "");
Expand Down