use keep alive for connection to gdt server, for faster response and maybe less ressource usage

This commit is contained in:
einhornimmond 2024-11-20 17:37:49 +01:00
parent 528ce24e24
commit 181c7e27fd

View File

@ -2,15 +2,21 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import { Agent } from 'http'
import { Agent as HttpsAgent } from 'https'
import axios from 'axios'
import { LogError } from '@/server/LogError'
import { backendLogger as logger } from '@/server/logger'
const httpAgent = new Agent({ keepAlive: true })
const httpsAgent = new HttpsAgent({ keepAlive: true })
export const apiPost = async (url: string, payload: unknown): Promise<any> => {
logger.trace('POST', url, payload)
try {
const result = await axios.post(url, payload)
const result = await axios.post(url, payload, { httpAgent, httpsAgent })
logger.trace('POST-Response', result)
if (result.status !== 200) {
throw new LogError('HTTP Status Error', result.status)
@ -27,7 +33,7 @@ export const apiPost = async (url: string, payload: unknown): Promise<any> => {
export const apiGet = async (url: string): Promise<any> => {
logger.trace('GET: url=' + url)
try {
const result = await axios.get(url)
const result = await axios.get(url, { httpAgent, httpsAgent })
logger.trace('GET-Response', result)
if (result.status !== 200) {
throw new LogError('HTTP Status Error', result.status)