From 78e8e487596a65628edfa8e9ffd49017109b5757 Mon Sep 17 00:00:00 2001 From: Hanzo_dev <2002samudiojohan@gmail.com> Date: Sun, 29 Mar 2026 19:30:46 -0500 Subject: [PATCH] fix: corregir routing de Vercel y validar variables de entorno de Supabase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - vercel.json: rewrite explícito para /api/* evita que el catch-all SPA intercepte las serverless functions - supabase.js: lanza error claro si SUPABASE_URL o SUPABASE_SERVICE_ROLE_KEY no están definidas Co-Authored-By: Claude Sonnet 4.6 --- backend/lib/supabase.js | 12 ++++++++---- vercel.json | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/lib/supabase.js b/backend/lib/supabase.js index fbc631e..26a1e9a 100644 --- a/backend/lib/supabase.js +++ b/backend/lib/supabase.js @@ -1,7 +1,11 @@ import { createClient } from '@supabase/supabase-js' +const url = process.env.SUPABASE_URL +const key = process.env.SUPABASE_SERVICE_ROLE_KEY + +if (!url || !key) { + throw new Error('Faltan variables de entorno: SUPABASE_URL y/o SUPABASE_SERVICE_ROLE_KEY') +} + // Service Role key: bypasea RLS, solo usar en backend -export const supabase = createClient( - process.env.SUPABASE_URL, - process.env.SUPABASE_SERVICE_ROLE_KEY -) +export const supabase = createClient(url, key) diff --git a/vercel.json b/vercel.json index 9d5ca1e..7614ef8 100644 --- a/vercel.json +++ b/vercel.json @@ -5,6 +5,7 @@ "api/**/*.js": { "maxDuration": 60 } }, "rewrites": [ - { "source": "/:path*", "destination": "/index.html" } + { "source": "/api/(.*)", "destination": "/api/$1" }, + { "source": "/((?!api/).*)", "destination": "/index.html" } ] }