Skip to content

Commit

Permalink
feat: Missing rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Jul 27, 2022
1 parent 7b775e7 commit fceaf57
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -65,6 +65,7 @@
"crypto-js": "^4.1.1",
"ejs": "^3.1.8",
"express": "^4.18.1",
"express-rate-limit": "^6.5.1",
"futoin-hkdf": "^1.5.1",
"knex": "^2.1.0",
"latest-version": "^5.1.0",
Expand Down
9 changes: 9 additions & 0 deletions src/ws/app.ts
@@ -1,6 +1,7 @@
import express, { Express, Request, Response } from 'express';
import { options } from './model/interface';
import cors from 'cors';
import { rateLimit } from 'express-rate-limit';

export function appExpress(options: options): Express {
const app = express();
Expand All @@ -15,6 +16,14 @@ export function appExpress(options: options): Express {
})
);

const limiter = rateLimit({
windowMs: 1*60*1000, // 1 minute
max: 5
});

// apply rate limiter to all requests
app.use(limiter);

const corsOptions: cors.CorsOptions = {
origin: '*',
};
Expand Down

0 comments on commit fceaf57

Please sign in to comment.