mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
16 lines
408 B
TypeScript
16 lines
408 B
TypeScript
import { Container } from 'typedi';
|
|
import { Request, Response, NextFunction } from 'express';
|
|
|
|
/**
|
|
* Rate limiter middleware.
|
|
*/
|
|
export default (req: Request, res: Response, next: NextFunction) => {
|
|
const requestRateLimiter = Container.get('rateLimiter.request');
|
|
|
|
requestRateLimiter.attempt(req.ip).then(() => {
|
|
next();
|
|
})
|
|
.catch(() => {
|
|
res.status(429).send('Too Many Requests');
|
|
});
|
|
} |