Skip to content

Commit 263db41

Browse files
committed
feat: move rate limiting after passport to leverage ctx.isAuthenticated and ctx.state.user in rate limiting id lookup
1 parent 54518e2 commit 263db41

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,6 @@ class API {
107107
// Basic auth
108108
if (this.config.auth) app.use(auth(this.config.auth));
109109

110-
// Rate limiting
111-
if (this.client && this.config.rateLimit)
112-
app.use(
113-
ratelimit({
114-
...this.config.rateLimit,
115-
db: this.client,
116-
logger: this.logger
117-
})
118-
);
119-
120110
// Remove trailing slashes
121111
app.use(removeTrailingSlashes());
122112

@@ -148,6 +138,16 @@ class API {
148138
// Passport
149139
if (this.passport) app.use(this.passport.initialize());
150140

141+
// Rate limiting
142+
if (this.client && this.config.rateLimit)
143+
app.use(
144+
ratelimit({
145+
...this.config.rateLimit,
146+
db: this.client,
147+
logger: this.logger
148+
})
149+
);
150+
151151
// Store the user's last ip address in the background
152152
if (this.config.storeIPAddress) {
153153
const storeIPAddress = new StoreIPAddress({

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"Nick Baugh <[email protected]> (http://niftylettuce.com/)"
1212
],
1313
"dependencies": {
14-
"@koa/router": "^11.0.0",
14+
"@koa/router": "^11.0.1",
1515
"@ladjs/i18n": "^8.0.1",
1616
"@ladjs/koa-simple-ratelimit": "^4.0.1",
1717
"@ladjs/passport": "^5.0.3",
@@ -50,7 +50,7 @@
5050
"ioredis": "^5.1.0",
5151
"ioredis-mock": "^8.2.2",
5252
"lint-staged": "13.0.3",
53-
"mongoose": "^6.4.2",
53+
"mongoose": "^6.4.3",
5454
"nyc": "^15.1.0",
5555
"remark-cli": "^11.0.0",
5656
"remark-preset-github": "^4.0.4",

0 commit comments

Comments
 (0)