// netlify/functions/notion-products.js // Subí este archivo tal cual si usás Netlify. // Variables de entorno necesarias: // NOTION_API_KEY=tu_secret_de_notion // NOTION_DATABASE_ID=tu_database_id exports.handler = async function () { try { const notionKey = process.env.NOTION_API_KEY; const databaseId = process.env.NOTION_DATABASE_ID; if (!notionKey || !databaseId) { return { statusCode: 500, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ error: "Faltan NOTION_API_KEY o NOTION_DATABASE_ID" }) }; } const response = await fetch(`https://api.notion.com/v1/databases/${databaseId}/query`, { method: "POST", headers: { "Authorization": `Bearer ${notionKey}`, "Notion-Version": "2022-06-28", "Content-Type": "application/json" }, body: JSON.stringify({ page_size: 100, sorts: [ { property: "Nombre", direction: "ascending" } ] }) }); const data = await response.json(); return { statusCode: 200, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" }, body: JSON.stringify(data) }; } catch (error) { return { statusCode: 500, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ error: "Error consultando Notion", details: error.message }) }; } };