use keep alive in disk cache and user counter

This commit is contained in:
Ajay
2022-12-05 17:06:00 -05:00
parent d7d5618985
commit cff2325aef
2 changed files with 19 additions and 5 deletions

View File

@@ -3,12 +3,18 @@ import { Logger } from "../utils/logger";
import { config } from "../config";
import { getIP } from "../utils/getIP";
import { NextFunction, Request, Response } from "express";
import { Agent } from "http";
const httpAgent = new Agent({ keepAlive: true });
export function userCounter(req: Request, res: Response, next: NextFunction): void {
if (req.method !== "OPTIONS") {
if (Math.random() < 1 / config.userCounterRatio) {
axios.post(`${config.userCounterURL}/api/v1/addIP?hashedIP=${getIP(req)}`)
.catch(() => Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`));
axios({
method: "post",
url: `${config.userCounterURL}/api/v1/addIP?hashedIP=${getIP(req)}`,
httpAgent
}).catch(() => Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`));
}
}