From 2aa416f9d9eeae5780ace36ec1c8819a82b66366 Mon Sep 17 00:00:00 2001 From: Hugo Arregui Date: Thu, 8 Feb 2024 09:36:30 -0300 Subject: [PATCH] fix: disable keep alive for local fetch requests --- src/localFetch.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/localFetch.ts b/src/localFetch.ts index 42501f3..6040ecd 100644 --- a/src/localFetch.ts +++ b/src/localFetch.ts @@ -1,4 +1,5 @@ import nodeFetch, { RequestInfo, RequestInit } from "node-fetch" +import * as http from 'http' import { IFetchComponent } from "@well-known-components/http-server" import { IConfigComponent } from "@well-known-components/interfaces" @@ -31,11 +32,13 @@ export async function createLocalFetchCompoment( const protocolHostAndProtocol = `http://${await configComponent.requireString( "HTTP_SERVER_HOST" )}:${await configComponent.requireNumber("HTTP_SERVER_PORT")}` + + const agent = new http.Agent({ keepAlive: false }) // test fetch, to hit our local server const localFetch: IFetchComponent = { async fetch(url: RequestInfo, initRequest?: RequestInit) { if (typeof url == "string" && url.startsWith("/")) { - return nodeFetch(protocolHostAndProtocol + url, { ...initRequest }) + return nodeFetch(protocolHostAndProtocol + url, { agent, ...initRequest }) } else { throw new Error("localFetch only works for local testing-URLs") }