Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of requests #163

Open
wants to merge 1 commit into
base: prod
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"cors": "^2.8.5",
"ethers": "^6.7.1",
"express": "^4.18.2",
"express-rate-limit": "^7.4.0",
"express-validator": "^7.0.1",
"firebase-admin": "^11.10.1",
"firebase-functions": "^4.4.1",
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import '@polkadot/api-augment';
// Fix end
import express from 'express';
import rateLimit from 'express-rate-limit';
import bodyParser from 'body-parser';
import * as functions from 'firebase-functions';
import cors from 'cors';
Expand All @@ -11,6 +12,14 @@ import { IControllerBase } from './controllers/IControllerBase';
import { ContainerTypes } from './containertypes';

const app = express();

// Limit the number or requests to 100 per minute.
const limiter = rateLimit({
windowMs: 1 * 60 * 1000,
max: 100,
});
app.use(limiter);

app.use(express.json({ limit: '5mb' }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4239,6 +4239,11 @@ expect@^29.0.0, expect@^29.6.3:
jest-message-util "^29.6.3"
jest-util "^29.6.3"

express-rate-limit@^7.4.0:
version "7.4.0"
resolved "https://registry.yarnpkg.com/express-rate-limit/-/express-rate-limit-7.4.0.tgz#5db412b8de83fa07ddb40f610c585ac8c1dab988"
integrity sha512-v1204w3cXu5gCDmAvgvzI6qjzZzoMWKnyVDk3ACgfswTQLYiGen+r8w0VnXnGMmzEN/g8fwIQ4JrFFd4ZP6ssg==

express-validator@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/express-validator/-/express-validator-7.0.1.tgz#435fac6b5fa838763f78eca05d2206317b92106e"
Expand Down
Loading