add keepalive option in JsonApi.getResponse

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen committed 2021-11-17 18:13:27 +02:00
1 parent 2446b6cf9b
commit 9aa5b5d875
1 file changed
+8
+8
View File
@@ -21,6 +21,8 @@
// Base http-service / json-api class
import { Agent as HttpAgent } from "http";
import { Agent as HttpsAgent } from "https";
import { merge } from "lodash";
import fetch, { Response, RequestInit } from "node-fetch";
import { stringify } from "querystring";
@@ -95,6 +97,12 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
reqInit.method = "get";
}
if (!reqInit.agent) {
const agentOpts = { keepAlive: true };
reqInit.agent = reqUrl.startsWith("https:") ? new HttpsAgent(agentOpts) : new HttpAgent(agentOpts);
}
if (query) {
const queryString = stringify(query);