/* Memoria del tablero */ let boardData = []; export default { async fetch(request, env) { /* CRITICO: Permisos CORS para que el HTML no se bloquee */ const corsHeaders = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET, POST, OPTIONS", "Access-Control-Allow-Headers": "Content-Type", }; /* Responde a la verificacion de seguridad del navegador */ if (request.method === "OPTIONS") { return new Response(null, { headers: corsHeaders }); } const url = new URL(request.url); /* RUTA GET: Manda los datos al tablero */ if (request.method === "GET" && url.pathname === "/get") { return new Response(JSON.stringify(boardData), { headers: { ...corsHeaders, "Content-Type": "application/json" } }); } /* RUTA POST: Recibe el VOY o NO VOY del jugador */ if (request.method === "POST" && url.pathname === "/set") { try { const { name, status } = await request.json(); const index = boardData.findIndex(p => p.name === name); if (index >= 0) { boardData[index].status = status; } else { boardData.push({ name, status }); } return new Response(JSON.stringify({ success: true }), { headers: { ...corsHeaders, "Content-Type": "application/json" } }); } catch (e) { return new Response("Error al guardar los datos", { status: 400, headers: corsHeaders }); } } /* RUTA RAIZ: Mensaje de confirmacion */ return new Response("Servidor CHULE BOARD PRO Activo ⚾🔥", { headers: corsHeaders }); } };