From 1d018cf12e42dd85145db083e8a741c6f6de1f3e Mon Sep 17 00:00:00 2001 From: Ivan Tymoshenko Date: Thu, 18 May 2023 15:29:58 +0200 Subject: [PATCH] feat: replace undici.Pool with undici.request --- lib/webhook.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/webhook.js b/lib/webhook.js index fd8a74e..7bd8065 100644 --- a/lib/webhook.js +++ b/lib/webhook.js @@ -1,7 +1,7 @@ 'use strict' const fp = require('fastify-plugin') -const { Pool } = require('undici') +const { request } = require('undici') const createError = require('@fastify/error') const notAllowed = new Set([ @@ -11,15 +11,8 @@ const notAllowed = new Set([ ]) module.exports = fp(async function (app, pluginOpts) { - const { - webhook: opts - } = pluginOpts + const url = pluginOpts.webhook.url - const origin = new URL(opts.url) - const path = origin.pathname - origin.pathname = '/' - const pool = new Pool(origin) - app.addHook('onClose', () => pool.close()) app.decorateRequest('createWebhookSession', async function () { const headers = {} for (const header of Object.keys(this.headers)) { @@ -31,8 +24,7 @@ module.exports = fp(async function (app, pluginOpts) { if (body) { headers['content-length'] = Buffer.byteLength(body) } - const res = await pool.request({ - path, + const res = await request(url, { method: 'POST', headers: { ...headers,