The signature verification process for webhooks has been abstracted. Instead of performing the check directly in the handleWebhook method, it has been moved to a separate service class: PostgresDatabaseWebhookVerifierService. This refactor improves modularity and enables extending or replacing the verification logic more comfortably. The WEBHOOK_SENDER_PROVIDER environment variable is used to determine which verifier service to use.
23 lines
535 B
TypeScript
23 lines
535 B
TypeScript
import { DatabaseWebhookHandlerService } from '@kit/database-webhooks';
|
|
|
|
const service = new DatabaseWebhookHandlerService();
|
|
|
|
const response = (status: number) => new Response(null, { status });
|
|
|
|
/**
|
|
* @name POST
|
|
* @description POST handler for the webhook route that handles the webhook event
|
|
* @param request
|
|
* @constructor
|
|
*/
|
|
export async function POST(request: Request) {
|
|
try {
|
|
// handle the webhook event
|
|
await service.handleWebhook(request);
|
|
|
|
return response(200);
|
|
} catch {
|
|
return response(500);
|
|
}
|
|
}
|