Skip to content

Latest commit

 

History

History
81 lines (58 loc) · 2.51 KB

README.md

File metadata and controls

81 lines (58 loc) · 2.51 KB

Strapi Upstash Ratelimit Plugin

Ratelimit your Strapi endpoints using globally distributed redis.

npm package version npm package daily downloads github stars github issues

Features

This plugin provides a way to apply Route based ratelimiting to prevent the abuse targeting your endpoints. It uses HTTP and Upstash Redis based ratelimiting under the hood.

The ratelimiting data is stored on a Redis database. You can set a strategy to define which algorithms or which rates to use per endpoint. You can also enable logging, to see the

Quickstart

Install

npm

npm install --save @upstash/strapi-plugin-upstash-ratelimit

yarn

yarn add @upstash/strapi-plugin-upstash-ratelimit

Create database

Create a new redis database on Upstash Console. See docs for further info related to creating a database.

Set up environment variables

Get the environment variables from Upstash Console, and set it to .env file as below:

UPSTASH_REDIS_REST_TOKEN="<YOUR_TOKEN>"
UPSTASH_REDIS_REST_URL="<YOUR_URL>"

Configure the Strapi plugin

In the ./config/plugins.ts file, set the configurations for ratelimiter.

export default () => ({
  "strapi-plugin-upstash-ratelimit": {
    enabled: true,
    config: {
      token: process.env.UPSTASH_REDIS_REST_TOKEN,
      url: process.env.UPSTASH_REDIS_REST_URL,
      strategy: [
        {
          methods: ["GET", "POST"],
          path: "*",
          limiter: {
            algorithm: "fixed-window",
            tokens: 10,
            window: "20s",
          },
        },
      ],
      prefix: "@strapi",
    },
  },
});

Documentation

See the documentation for more information details about this package.

License

See the