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

Merge to develop for final release #9

Merged
merged 51 commits into from
Feb 5, 2024
Merged

Merge to develop for final release #9

merged 51 commits into from
Feb 5, 2024

Conversation

thetutlage
Copy link
Member

@thetutlage thetutlage commented Feb 5, 2024

  • Remove container binding Adonis/Addons/Limiter in favor of container services and limiter.manager binding.
  • The import path for the limiter service has been change.
    - import { Limiter } from '@adonisjs/limiter/build/services'
    + import limiter from '@adonisjs/limiter/services/main'
  • Remove HttpLimiterConfigBuilder in favor of HttpLimiter. The API is still the same.
  • Remove Throttle middleware, since limiterManager.define method now returns a middleware function that can be applied to routes directly.
  • Remove property LimiterResponse.retryAfter in favor of LimiterResponse.availableIn.

Breaking change in HTTP limiters

The HTTP limiters defined using the Limiter.define method have been refactored and now the limiter.define method returns a middleware function that can be applied to a route. Following is a brief diff for the same.

Earlier

import { Limiter } from '@adonisjs/limiter/build/services'

export const { limiters } = Limiter
  .define('global', (ctx) => {
    return Limiter.allowRequests(1000).every('1 min')
  })

// INSIDE ROUTES FILE
Route.get('/api/reports/:id', () => {
}).middleware('throttle:global')

Now

import limiter from '@adonisjs/limiter/services/main'

export const throttle = limiter.define('global', (ctx) => {
  return limiter.allowRequests(1000).every('1 min')
})

// INSIDE ROUTES FILE
import { throttle } from '#start/limiter'

router.get('/api/reports/:id', () => {
}).use(throttle)

Features

  • Add clear method to stores and limiter manager to clear all the rate limiting data from the store. This could be helpful during testing. See docs for usage information.
  • Add limiter.attempt method run a callback if rate limiter requests have not been exhausted.
  • Add limiter.penalize method to exhaust requests when the provided callback throws an exception.
  • Add availableIn method to get the number of seconds to wait before the key becomes available.

Improvements

  • The config file has been improved a lot with usage of functions and there is no need for contracts/limiter.ts file.

@thetutlage thetutlage merged commit 4b16c22 into develop Feb 5, 2024
10 checks passed
@thetutlage thetutlage deleted the next branch February 5, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants