@perseidesjs/medusa-plugin-rate-limit
v2.0.2
Published
A simple rate-limit middleware for Medusa
Downloads
318
Maintainers
Readme
npm install @perseidesjs/medusa-plugin-rate-limit
// 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()],
},
],
})
// 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,
})],
},
],
})
//
import {
defineMiddlewares
} from "@medusajs/framework/http"
import { defaultRateLimit, configureDefaults } from '@perseidesjs/medusa-plugin-rate-limit'
// This will override the global default options for all routes
// Here, we set the limit to 1 request per 30 seconds
configureDefaults({
limit: 1,
window: 30,
})
export default defineMiddlewares({
routes: [
{
matcher: "/store/custom*",
method: "POST",
middlewares: [
// Uses the global default options
defaultRateLimit()
],
},
{
matcher: "/store/custom*",
method: "POST",
middlewares: [
// If the options are provided, they will ignore the global default options and use the provided ones
defaultRateLimit({
limit: 10,
window: 60,
})
],
},
],
})