-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypedRoutes.ts
20 lines (18 loc) · 1.01 KB
/
typedRoutes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { RoutePaths } from '@/shared/model/Routes';
import { Router } from 'express';
import { rateLimiterMiddleware } from './middleware/rateLimit';
const router = Router();
// We only expose a rate limited typed router because we want to apply the limiter to everything.
export const rateLimitedTypedRouter = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- handlers could be any express valid option
get: (path: RoutePaths, ...handlers: any[]) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises -- express has its own way of handling async middleware
return router.get(path, rateLimiterMiddleware, ...handlers);
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- handlers could be any express valid option
post: (path: RoutePaths, ...handlers: any[]) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises -- express has its own way of handling async middleware
return router.post(path, rateLimiterMiddleware, ...handlers);
},
router,
};