mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
Merge pull request #3392 from gradido/backend_keep_alive
feat(backend): speed up gdt request with keep alive connections
This commit is contained in:
commit
02a2b46cf5
5
backend/src/apis/ConnectionAgents.ts
Normal file
5
backend/src/apis/ConnectionAgents.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { Agent } from 'http'
|
||||
import { Agent as HttpsAgent } from 'https'
|
||||
|
||||
export const httpAgent = new Agent({ keepAlive: true })
|
||||
export const httpsAgent = new HttpsAgent({ keepAlive: true })
|
||||
@ -7,10 +7,12 @@ import axios from 'axios'
|
||||
import { LogError } from '@/server/LogError'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
|
||||
import { httpAgent, httpsAgent } from './ConnectionAgents'
|
||||
|
||||
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 +29,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)
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
import axios from 'axios'
|
||||
|
||||
import { httpAgent, httpsAgent } from '@/apis/ConnectionAgents'
|
||||
import { CONFIG } from '@/config'
|
||||
import { LogError } from '@/server/LogError'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
@ -126,9 +127,10 @@ export async function createGmsUser(apiKey: string, user: GmsUser): Promise<bool
|
||||
accept: 'application/json',
|
||||
language: 'en',
|
||||
timezone: 'UTC',
|
||||
connection: 'keep-alive',
|
||||
authorization: apiKey,
|
||||
},
|
||||
httpAgent,
|
||||
httpsAgent,
|
||||
}
|
||||
try {
|
||||
const result = await axios.post(baseUrl.concat(service), user, config)
|
||||
@ -160,9 +162,10 @@ export async function updateGmsUser(apiKey: string, user: GmsUser): Promise<bool
|
||||
accept: 'application/json',
|
||||
language: 'en',
|
||||
timezone: 'UTC',
|
||||
connection: 'keep-alive',
|
||||
authorization: apiKey,
|
||||
},
|
||||
httpAgent,
|
||||
httpsAgent,
|
||||
}
|
||||
try {
|
||||
const result = await axios.patch(baseUrl.concat(service), user, config)
|
||||
@ -197,9 +200,10 @@ export async function verifyAuthToken(
|
||||
accept: 'application/json',
|
||||
language: 'en',
|
||||
timezone: 'UTC',
|
||||
connection: 'keep-alive',
|
||||
// authorization: apiKey,
|
||||
},
|
||||
httpAgent,
|
||||
httpsAgent,
|
||||
}
|
||||
try {
|
||||
const result = await axios.get(baseUrl.concat(service), config)
|
||||
|
||||
@ -20,7 +20,9 @@ export class HumHubClient {
|
||||
|
||||
// eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function
|
||||
private constructor() {
|
||||
this.restClient = new RestClient('gradido-backend', CONFIG.HUMHUB_API_URL)
|
||||
this.restClient = new RestClient('gradido-backend', CONFIG.HUMHUB_API_URL, undefined, {
|
||||
keepAlive: true,
|
||||
})
|
||||
logger.info('create rest client for', CONFIG.HUMHUB_API_URL)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user