How to use

If you want to start restricting certain routes, you can import the defaultRateLimit middleware from the plugin and then use it as follows:

src/api/middlewares.ts
import { defineMiddlewares } from "@medusajs/medusa"
import { defaultRateLimit } from '@perseidesjs/medusa-plugin-rate-limit'

export default defineMiddlewares({
  routes: [
    {
      matcher: "/store/custom*",
      middlewares: [defaultRateLimit()],
    },
  ],
})

You can also pass some custom options to have a complete control over the rate limiting mechanism as follows:

src/api/middlewares.ts
import { defineMiddlewares } from "@medusajs/medusa"
import { defaultRateLimit } from '@perseidesjs/medusa-plugin-rate-limit'

export default defineMiddlewares({
  routes: [
    {
      matcher: "/store/custom*",
      middlewares: [defaultRateLimit({
				limit: 10,
				window: 60,
			})],
    },
  ],
})

In this example, the rate limiting mechanism will allow 10 requests per minute per IP address.

To learn more about advanced customization and configuration, check out the Customization section.