Advertisement
MatiGe

server

May 12th, 2025
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let storedCode = null;
  2.  
  3. exports.handler = async (event) => {
  4.     if (event.httpMethod === 'POST') {
  5.         try {
  6.             const body = JSON.parse(event.body);
  7.             const code = body.codigo;
  8.             if (code) {
  9.                 storedCode = code;
  10.                 console.log(`Código guardado por la función: ${storedCode}`);
  11.                 return {
  12.                     statusCode: 200,
  13.                     body: JSON.stringify({ mensaje: 'Código guardado exitosamente.' }),
  14.                 };
  15.             } else {
  16.                 return {
  17.                     statusCode: 400,
  18.                     body: JSON.stringify({ error: 'No se recibió ningún código.' }),
  19.                 };
  20.             }
  21.         } catch (error) {
  22.             console.error('Error al procesar el cuerpo de la petición:', error);
  23.             return {
  24.                 statusCode: 400,
  25.                 body: JSON.stringify({ error: 'Cuerpo de la petición inválido.' }),
  26.             };
  27.         }
  28.     } else {
  29.         return {
  30.             statusCode: 405,
  31.             body: JSON.stringify({ error: 'Método no permitido. Usa POST para guardar el código.' }),
  32.         };
  33.     }
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement