Skip to content

Commit

Permalink
feat: replace undici.Pool with undici.request
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-tymoshenko committed May 18, 2023
1 parent 6b09104 commit 1d018cf
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/webhook.js
Original file line number Diff line number Diff line change
@@ -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([
Expand All @@ -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)) {
Expand All @@ -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,
Expand Down

0 comments on commit 1d018cf

Please sign in to comment.