Skip to content

Commit

Permalink
fix: disable keep alive for local fetch requests (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoArregui authored Feb 8, 2024
1 parent 25c5df4 commit de171dd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/localFetch.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit de171dd

Please sign in to comment.