Created
March 6, 2025 16:56
-
-
Save delineas/a24dfd819a8eb1c05adf4c2629012392 to your computer and use it in GitHub Desktop.
Minimal webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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