/** * Edge Function: main (relay) * Enruta todas las requests al worker de la función correspondiente. * Requerido por supabase/edge-runtime en self-hosted (--main-service). * No expuesto directamente — solo opera como router interno. */ const FUNCTIONS = ['invite-user', 'revoke-user'] Deno.serve(async (req: Request) => { const url = new URL(req.url) // Extraer nombre de función del path: /functions/v1/invite-user → invite-user const segments = url.pathname.split('/').filter(Boolean) const functionName = segments[segments.length - 1] if (!functionName || !FUNCTIONS.includes(functionName)) { return new Response( JSON.stringify({ error: `Función no encontrada: ${functionName}` }), { status: 404, headers: { 'Content-Type': 'application/json' } }, ) } const servicePath = `/home/deno/functions/${functionName}` try { // EdgeRuntime.userWorkers es el API del supabase/edge-runtime para crear workers por función const worker = await EdgeRuntime.userWorkers.create({ servicePath }) return await worker.fetch(req) } catch (err) { const message = err instanceof Error ? err.message : String(err) return new Response( JSON.stringify({ error: message }), { status: 500, headers: { 'Content-Type': 'application/json' } }, ) } })