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

Rate limiter #37

Merged
merged 3 commits into from
Sep 14, 2024
Merged

Rate limiter #37

merged 3 commits into from
Sep 14, 2024

Conversation

9helix
Copy link
Collaborator

@9helix 9helix commented Sep 9, 2024

Description

Added rate limiter for the API using the Upstash rate limit.
Upstash account and Redis database created on it needed. More info: https://upstash.com/docs/redis/overall/getstarted
Credentials need to be provided in .env like this:
UPSTASH_REDIS_REST_URL="[database link]"
UPSTASH_REDIS_REST_TOKEN="[database token]"

Change summary

  • Initialized limiter
  • Set up error throwing when limit is exceeded

Checklist

  • I have performed a self-review of my code
  • I tested locally
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New package or package update introduced

@9helix 9helix linked an issue Sep 9, 2024 that may be closed by this pull request
@9helix
Copy link
Collaborator Author

9helix commented Sep 12, 2024

Now I've added the ability to enable the limiter (disabled by default) from the .env file using the variable RATE_LIMITER_ENABLED. Set it to either true or false.

src/server/api/trpc.ts Outdated Show resolved Hide resolved
src/env.js Show resolved Hide resolved
Copy link
Collaborator

@IMilja IMilja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me. I requested two small changes and after you implement them we can merge the changes :)

@9helix 9helix merged commit 0523a2d into main Sep 14, 2024
1 check passed
@9helix 9helix deleted the feat/rate-limit branch September 14, 2024 16:36
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.

Add rate limiter to Next.js server
2 participants