-
Notifications
You must be signed in to change notification settings - Fork 5
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
Rate Limit API Calls #402
Open
nik-dange
wants to merge
6
commits into
master
Choose a base branch
from
feature/rate-limiter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rate Limit API Calls #402
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82446cb
removed other changes and added rate limit logic
nik-dange 8494610
idk what im doing
nik-dange 3a3e8fc
idk
nik-dange d7ac9f1
i hate this
nik-dange 58cc214
crying
nik-dange 5efedcc
Merge branch 'master' into feature/rate-limiter
dowhep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import rateLimit from 'express-rate-limit'; | ||
|
||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 5, | ||
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers | ||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers | ||
}); | ||
|
||
console.log("HELLO"); | ||
|
||
export function RateLimit(): MethodDecorator { | ||
return function (_target: any, _key: string, descriptor: PropertyDescriptor) { | ||
const originalMethod = descriptor.value; | ||
console.log("originalMethod", originalMethod); | ||
descriptor.value = function (...args: any[]) { | ||
const context = args[0]; | ||
limiter(context.req, context.res, () => {}); | ||
return originalMethod.apply(this, args); | ||
}; | ||
return descriptor; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers'; | ||
import * as express from 'express'; | ||
import { rateLimit } from 'express-rate-limit'; | ||
// import { Config } from '../../config'; | ||
|
||
@Middleware({ type: 'before' }) | ||
export class RateLimiter implements ExpressMiddlewareInterface { | ||
private limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, | ||
max: 5, | ||
message: 'Too many requests, please try again later.', | ||
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers | ||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers | ||
}); | ||
|
||
use(req: express.Request, res: express.Response, next: express.NextFunction) { | ||
return this.limiter(req, res, next); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2392,6 +2392,11 @@ expect@^27.5.1: | |
jest-matcher-utils "^27.5.1" | ||
jest-message-util "^27.5.1" | ||
|
||
[email protected]: | ||
version "6.11.2" | ||
resolved "https://registry.yarnpkg.com/express-rate-limit/-/express-rate-limit-6.11.2.tgz#6c42035603d3b52e4e2fb59f6ebaa89e628ef980" | ||
integrity sha512-a7uwwfNTh1U60ssiIkuLFWHt4hAC5yxlLGU2VP0X4YNlyEDZAqF4tK3GD3NSitVBrCQmQ0++0uOyFOgC2y4DDw== | ||
|
||
express-session@^1.17.1: | ||
version "1.17.2" | ||
resolved "https://registry.yarnpkg.com/express-session/-/express-session-1.17.2.tgz#397020374f9bf7997f891b85ea338767b30d0efd" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this is ugly as well, it feels weird adding this app.set here. I don't think there's a way with our routing-controllers package to have the app.set config set, but maybe there's other ideas out there