11import { DifferV3 } from '@api7/adc-differ' ;
22import * as ADCSDK from '@api7/adc-sdk' ;
3+ import { HttpAgent , HttpOptions , HttpsAgent } from 'agentkeepalive' ;
34import type { RequestHandler } from 'express' ;
45import { omit , toString } from 'lodash' ;
56import { lastValueFrom , toArray } from 'rxjs' ;
@@ -14,6 +15,25 @@ import { check } from '../linter';
1415import { logger } from './logger' ;
1516import { SyncInput , type SyncInputType } from './schema' ;
1617
18+ // create connection pool
19+ const keepAlive : HttpOptions = {
20+ keepAlive : true ,
21+ maxSockets : 256 , // per host
22+ maxFreeSockets : 16 , // per host free
23+ freeSocketTimeout : 60000 ,
24+ } ;
25+ const httpAgent = new HttpAgent ( keepAlive ) ;
26+
27+ //TODO: dynamic rejectUnauthorized and support mTLS
28+ const httpsAgent = new HttpsAgent ( {
29+ rejectUnauthorized : true ,
30+ ...keepAlive ,
31+ } ) ;
32+ const httpsInsecureAgent = new HttpsAgent ( {
33+ rejectUnauthorized : false ,
34+ ...keepAlive ,
35+ } ) ;
36+
1737export const syncHandler : RequestHandler <
1838 unknown ,
1939 unknown ,
@@ -46,12 +66,13 @@ export const syncHandler: RequestHandler<
4666 fillLabels ( local , task . opts . labelSelector ) ;
4767
4868 // load and filter remote configuration
49- //TODO: merged with the listr task
5069 const backend = loadBackend ( task . opts . backend , {
5170 ...task . opts ,
5271 server : Array . isArray ( task . opts . server )
5372 ? task . opts . server . join ( ',' )
5473 : task . opts . server ,
74+ httpAgent,
75+ httpsAgent : task . opts . tlsSkipVerify ? httpsInsecureAgent : httpsAgent ,
5576 } ) ;
5677
5778 backend . on ( 'AXIOS_DEBUG' , ( { description, response } ) =>
0 commit comments