Skip to content

Instantly share code, notes, and snippets.

@delineas
Created March 6, 2025 16:56
Show Gist options
  • Select an option

  • Save delineas/a24dfd819a8eb1c05adf4c2629012392 to your computer and use it in GitHub Desktop.

Select an option

Save delineas/a24dfd819a8eb1c05adf4c2629012392 to your computer and use it in GitHub Desktop.
Minimal webhook
// PORT=4242 node webhook.mjs
import http from 'http';
const PORT = process.env.PORT || 3000;
const server = http.createServer((req, res) => {
let body = [];
req.on('data', (chunk) => {
body.push(chunk);
});
req.on('end', () => {
if (body.length) {
body = Buffer.concat(body).toString();
try {
const data = JSON.parse(body);
console.log('Datos recibidos:', JSON.stringify(data, null, 2));
} catch (error) {
console.log('Datos recibidos (no JSON):', body);
}
} else {
console.log('Petición recibida sin cuerpo');
}
res.writeHead(200, { 'Content-Type': 'application/json' });
const responseData = JSON.stringify({
status: 'success',
message: 'Datos recibidos correctamente'
});
res.end(responseData);
});
});
server.listen(PORT, () => {
console.log(`Servidor webhook escuchando en http://localhost:${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment