-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow override user rate limit and user agent (#2803)
* feat: allow override user rate limit - improve user_agent config allow string * chore: fix tests * chore: refactor userRateLimit * chore: remove comment * chore: optional prop * chore: refactor limiter * chore: refactor endpoints * chore: fix undefined * chore: fix params * chore: fix params * chore: update ui * chore: refactor limiter * chore: fix tests * chore: fix test
- Loading branch information
1 parent
f64e403
commit 5b1264c
Showing
32 changed files
with
192 additions
and
179 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import { Response, Router } from 'express'; | ||
import { limiter } from '../../../user-rate-limit'; | ||
import profile from './profile'; | ||
import token from './token'; | ||
import v1Search from './search'; | ||
|
||
export default (auth, storage, config) => { | ||
const route = Router(); /* eslint new-cap: 0 */ | ||
route.use(limiter); | ||
route.use('/-/npm/v1/', profile(auth)); | ||
route.use('/-/npm/v1/', profile(auth, config)); | ||
route.use('/-/npm/v1/', token(auth, storage, config)); | ||
return route; | ||
}; |
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
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,11 @@ | ||
import RateLimit from 'express-rate-limit'; | ||
import { RateLimit as RateLimitType } from '@verdaccio/types'; | ||
|
||
const limiter = (rateLimitOptions: RateLimitType) => { | ||
// @ts-ignore | ||
return new RateLimit({ | ||
...rateLimitOptions, | ||
}); | ||
}; | ||
|
||
export { limiter }; |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
import { Response, Router } from 'express'; | ||
import { limiter } from '../../rate-limiter'; | ||
import packageApi from './package'; | ||
import search from './search'; | ||
import user from './user'; | ||
|
||
export default (auth, storage, config) => { | ||
const route = Router(); /* eslint new-cap: 0 */ | ||
route.use( | ||
'/data/', | ||
limiter({ | ||
windowMs: 2 * 60 * 1000, // 2 minutes | ||
max: 5000, // limit each IP to 1000 requests per windowMs | ||
...config?.web?.rateLimit, | ||
}) | ||
); | ||
route.use('/data/', packageApi(storage, auth, config)); | ||
route.use('/data/', search(storage, auth)); | ||
route.use('/sec/', limiter(config?.userRateLimit)); | ||
route.use('/sec/', user(auth, storage)); | ||
return route; | ||
}; |
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
Oops, something went wrong.