feat(webhook): use strapi fetch in webhooks

This commit is contained in:
nathan-pichon 2023-04-13 11:26:52 +02:00
parent e696b13c34
commit 50a2e58dda
No known key found for this signature in database
2 changed files with 5 additions and 4 deletions

View File

@ -395,6 +395,7 @@ class Strapi {
eventHub: this.eventHub,
logger: this.log,
configuration: this.config.get('server.webhooks', {}),
fetch: this.fetch,
});
this.registerInternalHooks();

View File

@ -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,