addEventListener("fetch", event => { event.respondWith(handleRequest(event.request)); }); async function handleRequest(request) { const url = new URL(request.url); // ── POST /login → imposta cookie server-side if (request.method === "POST" && url.pathname === "/login") { const body = await request.json(); if (body.pin === "1234") { const html = JSON.stringify({ ok: true }); return new Response(html, { headers: { "Content-Type": "application/json", // 🔑 Cookie HttpOnly impostato dal SERVER — iOS lo rispetta come prima parte "Set-Cookie": "sessione=attiva; Path=/; Max-Age=2592000; HttpOnly; SameSite=Lax" } }); } return new Response(JSON.stringify({ ok: false }), { headers: { "Content-Type": "application/json" } }); } // ── GET / → controlla se il cookie esiste già const cookie = request.headers.get("Cookie") || ""; const loggato = cookie.includes("sessione=attiva"); const html = `
PIN di test: 1234