From 50a2e58dda32904a07a1d378f50d1fadeccb1b29 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Thu, 13 Apr 2023 11:26:52 +0200 Subject: [PATCH] feat(webhook): use strapi fetch in webhooks --- packages/core/strapi/lib/Strapi.js | 1 + packages/core/strapi/lib/services/webhook-runner.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index ba6a0639c9..f5b2bf48d7 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -395,6 +395,7 @@ class Strapi { eventHub: this.eventHub, logger: this.log, configuration: this.config.get('server.webhooks', {}), + fetch: this.fetch, }); this.registerInternalHooks(); diff --git a/packages/core/strapi/lib/services/webhook-runner.js b/packages/core/strapi/lib/services/webhook-runner.js index 77b6477f92..05d97f1a46 100644 --- a/packages/core/strapi/lib/services/webhook-runner.js +++ b/packages/core/strapi/lib/services/webhook-runner.js @@ -6,7 +6,6 @@ const debug = require('debug')('strapi:webhook'); const _ = require('lodash'); -const fetch = require('node-fetch'); const WorkerQueue = require('./worker-queue'); @@ -15,12 +14,13 @@ const defaultConfiguration = { }; class WebhookRunner { - constructor({ eventHub, logger, configuration = {} }) { - debug('Initialized webhook runer'); + constructor({ eventHub, logger, configuration = {}, fetch }) { + debug('Initialized webhook runner'); this.eventHub = eventHub; this.logger = logger; this.webhooksMap = new Map(); this.listeners = new Map(); + this.fetch = fetch; if (typeof configuration !== 'object') { throw new Error( @@ -76,7 +76,7 @@ class WebhookRunner { run(webhook, event, info = {}) { const { url, headers } = webhook; - return fetch(url, { + return this.fetch(url, { method: 'post', body: JSON.stringify({ event,