Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

KB-RolePlay/oak-rate-limit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This fork is no longer used by our team.

oak-rate-limit

deno version Discord GitHub release (latest by date including pre-releases)

Rate limiter for Oak Server on Deno

Description

A Simple Rate Limiter for Oak Server on Deno inspired by express-rate-limit. It's currently under development and if you'd like to contribute, feel free to make a PR!

Features

  • Custom Cache Stores Support. Currently using Map by default (more coming soon).
  • Timestamp Comparisons instead of Intervals for Efficiency.
  • Custom handlers, window duration, max requests, status code, and error message support.

Usage

import { RateLimiter } from "https://deno.land/x/oak_rate_limit/mod.ts";

const rateLimit = RateLimiter({
  store: STORE, // Using MapStore by default.
  windowMs: 1000, // Window for the requests that can be made in miliseconds.
  max: (_ctx: Context) => [100, "default"], // Max requests within the predefined window with a unique max value name.
  headers: true, // Default true, it will add the headers X-RateLimit-Limit, X-RateLimit-Remaining.
  message: "Too many requests, please try again later.", // Default message if rate limit reached.
  statusCode: 429, // Default status code if rate limit reached.
  ipHeader: null, // If you want to don't use a custom header to get the request source IP.
});

app.use(await rateLimit);

Configuration

onRateLimit(opt, ctx, next)

Define a custom method to handle when the rate limit has been reached. The default implementation will send a 429 status code and the message defined in the message option.

skip(ctx)

Define a custom method to skip/whitelist the rate limit. The default implementation will return false.

Liked The Project?

ko-fi

License

Apache License 2.0

About

Rate-limiting middleware for Oak server on Deno

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • TypeScript 100.0%