fix middlewares

This commit is contained in:
Shane C 2024-08-27 11:57:45 -04:00
parent 410a786497
commit 25941e0437
Signed by: shane
GPG key ID: E46B5FEA35B22FF9
4 changed files with 11 additions and 11 deletions

View file

@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from "express";
import { app } from "..";
app.use('*', (req: Request, res: Response, next: NextFunction) => {
app.use('*', (_req: Request, res: Response, next: NextFunction) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, x-auth-user, x-auth-token');
res.header('Access-Control-Allow-Methods', '*');

View file

@ -1,7 +1,7 @@
import { Request, Response } from "express";
import { Request, Response, NextFunction } from "express";
import { app, logger } from "..";
app.use('*', (req: Request, _res: Response, next: () => void) => {
app.use('*', (req: Request, _res: Response, next: NextFunction) => {
logger.debug(`${req.method} ${req.url}`);
next();
});

View file

@ -20,7 +20,7 @@ class RateLimiter {
const ip = req.ip;
const reqId = ulid();
// ratelimit:ip_address_base64:route_base64
const redisKey = `ratelimit:${Buffer.from(ip).toString('base64')}:${Buffer.from(this.route).toString('base64')}`;
const redisKey = `ratelimit:${Buffer.from(ip!).toString('base64')}:${Buffer.from(this.route).toString('base64')}`;
const reqs = await redis.SCARD(redisKey);
if (reqs >= this.limit) {
logger.debug(`Ratelimiter: IP address exceeded ratelimit for ${this.route} [${this.limit}/${this.timeframe}]`);

View file

@ -1,4 +1,4 @@
import { Request } from "express";
import { Request, Response, NextFunction } from "express";
import { Collection, Db } from "mongodb";
import { app, SESSION_LIFETIME } from "..";
@ -8,7 +8,7 @@ export function initializeSessionsMiddleware(db: Db) {
sessionsCollection = db.collection('sessions');
}
app.use('*', async (req: Request, next: () => void) => {
app.use('*', async (req: Request, _res: Response, next: NextFunction) => {
next();
const user = req.header('x-auth-user');
const token = req.header('x-auth-token');