28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
// Listener HTTP mínimo, solo para esta prueba: simula sap-webhook-api pero
|
|||
|
|
// en vez de guardar en Postgres, escribe cada POST recibido como JSON en
|
||
|
|
// tmp-test-events/ para poder inspeccionarlo. Se borra todo (este archivo
|
||
|
|
// y la carpeta) al terminar la prueba.
|
||
|
|
import { createServer } from 'node:http';
|
||
|
|
import { writeFileSync } from 'node:fs';
|
||
|
|
import { fileURLToPath } from 'node:url';
|
||
|
|
|
||
|
|
const outDir = fileURLToPath(new URL('../tmp-test-events/', import.meta.url));
|
||
|
|
const port = 4100;
|
||
|
|
|
||
|
|
const server = createServer((req, res) => {
|
||
|
|
let body = '';
|
||
|
|
req.on('data', (chunk) => (body += chunk));
|
||
|
|
req.on('end', () => {
|
||
|
|
console.log(`[fake-webhook] ${req.method} ${req.url}`);
|
||
|
|
if (req.method === 'POST') {
|
||
|
|
const fileName = `${Date.now()}.json`;
|
||
|
|
writeFileSync(`${outDir}${fileName}`, body);
|
||
|
|
console.log(`[fake-webhook] guardado: tmp-test-events/${fileName}`);
|
||
|
|
console.log(body);
|
||
|
|
}
|
||
|
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||
|
|
res.end(JSON.stringify({ received: true }));
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
server.listen(port, () => console.log(`[fake-webhook] escuchando en http://127.0.0.1:${port}`));
|