mirror of
https://github.com/strapi/strapi.git
synced 2025-09-27 17:29:14 +00:00
feat(webhook): use strapi fetch in webhooks
This commit is contained in:
parent
e696b13c34
commit
50a2e58dda
@ -395,6 +395,7 @@ class Strapi {
|
|||||||
eventHub: this.eventHub,
|
eventHub: this.eventHub,
|
||||||
logger: this.log,
|
logger: this.log,
|
||||||
configuration: this.config.get('server.webhooks', {}),
|
configuration: this.config.get('server.webhooks', {}),
|
||||||
|
fetch: this.fetch,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.registerInternalHooks();
|
this.registerInternalHooks();
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
const debug = require('debug')('strapi:webhook');
|
const debug = require('debug')('strapi:webhook');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const fetch = require('node-fetch');
|
|
||||||
|
|
||||||
const WorkerQueue = require('./worker-queue');
|
const WorkerQueue = require('./worker-queue');
|
||||||
|
|
||||||
@ -15,12 +14,13 @@ const defaultConfiguration = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class WebhookRunner {
|
class WebhookRunner {
|
||||||
constructor({ eventHub, logger, configuration = {} }) {
|
constructor({ eventHub, logger, configuration = {}, fetch }) {
|
||||||
debug('Initialized webhook runer');
|
debug('Initialized webhook runner');
|
||||||
this.eventHub = eventHub;
|
this.eventHub = eventHub;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.webhooksMap = new Map();
|
this.webhooksMap = new Map();
|
||||||
this.listeners = new Map();
|
this.listeners = new Map();
|
||||||
|
this.fetch = fetch;
|
||||||
|
|
||||||
if (typeof configuration !== 'object') {
|
if (typeof configuration !== 'object') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -76,7 +76,7 @@ class WebhookRunner {
|
|||||||
run(webhook, event, info = {}) {
|
run(webhook, event, info = {}) {
|
||||||
const { url, headers } = webhook;
|
const { url, headers } = webhook;
|
||||||
|
|
||||||
return fetch(url, {
|
return this.fetch(url, {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
event,
|
event,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user