File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,18 @@ import { Logger } from "../utils/logger";
3
3
import { config } from "../config" ;
4
4
import { getIP } from "../utils/getIP" ;
5
5
import { NextFunction , Request , Response } from "express" ;
6
+ import { Agent } from "http" ;
7
+
8
+ const httpAgent = new Agent ( { keepAlive : true } ) ;
6
9
7
10
export function userCounter ( req : Request , res : Response , next : NextFunction ) : void {
8
11
if ( req . method !== "OPTIONS" ) {
9
12
if ( Math . random ( ) < 1 / config . userCounterRatio ) {
10
- axios . post ( `${ config . userCounterURL } /api/v1/addIP?hashedIP=${ getIP ( req ) } ` )
11
- . catch ( ( ) => Logger . debug ( `Failing to connect to user counter at: ${ config . userCounterURL } ` ) ) ;
13
+ axios ( {
14
+ method : "post" ,
15
+ url : `${ config . userCounterURL } /api/v1/addIP?hashedIP=${ getIP ( req ) } ` ,
16
+ httpAgent
17
+ } ) . catch ( ( ) => Logger . debug ( `Failing to connect to user counter at: ${ config . userCounterURL } ` ) ) ;
12
18
}
13
19
}
14
20
Original file line number Diff line number Diff line change 1
1
import axios , { AxiosError } from "axios" ;
2
+ import { Agent } from "http" ;
2
3
import { config } from "../config" ;
3
4
import { Logger } from "./logger" ;
4
5
6
+ const httpAgent = new Agent ( { keepAlive : true } ) ;
7
+
5
8
class DiskCache {
6
9
async set ( key : string , value : unknown ) : Promise < boolean > {
7
10
if ( ! config . diskCacheURL ) return false ;
8
11
9
12
try {
10
- const result = await axios . post ( `${ config . diskCacheURL } /api/v1/item` , {
11
- key,
12
- value
13
+ const result = await axios ( {
14
+ method : "post" ,
15
+ url : `${ config . diskCacheURL } /api/v1/item` ,
16
+ data : {
17
+ key,
18
+ value
19
+ } ,
20
+ httpAgent
13
21
} ) ;
14
22
15
23
return result . status === 200 ;
You can’t perform that action at this time.
0 commit comments