simplifica un poco los logs para que no sean tan pesados de parsear

main
borja 3 months ago
parent 4bc78f476c
commit 3d87aead2c

@ -39,22 +39,23 @@ export class WebhookServer {
} }
if (process.env.NODE_ENV !== 'test') { if (process.env.NODE_ENV !== 'test') {
console.log(' Incoming webhook request:', { console.log(' Incoming webhook request:')
method: request.method, // console.log(' Incoming webhook request:', {
path: url.pathname, // method: request.method,
time: new Date().toISOString() // path: url.pathname,
}); // time: new Date().toISOString()
// });
} }
// 1. Method validation // 1. Method validation
if (request.method !== 'POST') { if (request.method !== 'POST') {
return new Response('Method not allowed', { status: 405 }); return new Response('🚫 Method not allowed', { status: 405 });
} }
// 2. Content-Type validation // 2. Content-Type validation
const contentType = request.headers.get('content-type'); const contentType = request.headers.get('content-type');
if (!contentType?.includes('application/json')) { if (!contentType?.includes('application/json')) {
return new Response('Invalid content type', { status: 400 }); return new Response('🚫 Invalid content type', { status: 400 });
} }
try { try {
@ -62,13 +63,13 @@ export class WebhookServer {
const payload = await request.json() as WebhookPayload; const payload = await request.json() as WebhookPayload;
if (!payload.event || !payload.instance) { if (!payload.event || !payload.instance) {
return new Response('Invalid payload', { status: 400 }); return new Response('🚫 Invalid payload', { status: 400 });
} }
// 4. Verify instance matches (skip in test environment unless TEST_VERIFY_INSTANCE is set) // 4. Verify instance matches (skip in test environment unless TEST_VERIFY_INSTANCE is set)
if ((process.env.NODE_ENV !== 'test' || process.env.TEST_VERIFY_INSTANCE) && if ((process.env.NODE_ENV !== 'test' || process.env.TEST_VERIFY_INSTANCE) &&
payload.instance !== process.env.EVOLUTION_API_INSTANCE) { payload.instance !== process.env.EVOLUTION_API_INSTANCE) {
return new Response('Invalid instance', { status: 403 }); return new Response('🚫 Invalid instance', { status: 403 });
} }
// 5. Route events // 5. Route events

Loading…
Cancel
Save