From 30bfedeb9072029cae403a62fa9d6a0c55f000a0 Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Mon, 6 Nov 2023 02:16:28 +0000 Subject: [PATCH] fix: ratelimiting --- package-lock.json | 2 +- packages/medusa-plugin-strapi-ts/README.md | 4 ++++ packages/medusa-plugin-strapi-ts/package.json | 2 +- .../medusa-plugin-strapi-ts/src/api/routes/hooks/index.ts | 4 ++-- yarn.lock | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4dfe549d..5d9aac19 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55400,7 +55400,7 @@ "license": "MIT" }, "packages/medusa-plugin-strapi-ts": { - "version": "5.0.16", + "version": "5.0.17", "license": "MIT", "dependencies": { "@types/bcrypt": "^5.0.0", diff --git a/packages/medusa-plugin-strapi-ts/README.md b/packages/medusa-plugin-strapi-ts/README.md index e8ddf7c4..1f3aca71 100644 --- a/packages/medusa-plugin-strapi-ts/README.md +++ b/packages/medusa-plugin-strapi-ts/README.md @@ -94,6 +94,10 @@ const strapiOptions = auto_start?: boolean; - starts the interface automatically along with medusa, not recommended as the medusa server may not be ready to sync as soon as strapi is ready max_page_size?: number; +##### advanced environemental options + STAPI_HOOKS_MAX_REQUESTS - number of requests before hooks ratelimit kicksin + STAPI_HOOKS_MAX_DELAY - number of requests before hooks ratelimit window + ## Using Strapi Plugin diff --git a/packages/medusa-plugin-strapi-ts/package.json b/packages/medusa-plugin-strapi-ts/package.json index d8ecabfc..cbb56efe 100644 --- a/packages/medusa-plugin-strapi-ts/package.json +++ b/packages/medusa-plugin-strapi-ts/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-strapi-ts", - "version": "5.0.16", + "version": "5.0.17", "description": "A plugin for medusa to use strapi in the backend as the cms in typescript", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/medusa-plugin-strapi-ts/src/api/routes/hooks/index.ts b/packages/medusa-plugin-strapi-ts/src/api/routes/hooks/index.ts index e0331c3b..567771e9 100644 --- a/packages/medusa-plugin-strapi-ts/src/api/routes/hooks/index.ts +++ b/packages/medusa-plugin-strapi-ts/src/api/routes/hooks/index.ts @@ -9,8 +9,8 @@ import strapiSignal from '../../controllers/hooks/strapi-signal'; import rateLimiter from 'express-rate-limit'; const limiter = rateLimiter({ - max: 5, - windowMs: 10000, // 10 seconds + max: parseInt(process.env.STAPI_HOOKS_MAX_REQUESTS ?? '100') || 100, + windowMs: parseInt(process.env.STAPI_HOOKS_MAX_DELAY ?? '100000') || 100000, // 100 seconds message: "You can't make any more requests at the moment. Try again later", }); const hooksRouter = Router(); diff --git a/yarn.lock b/yarn.lock index 067165b8..bb4fade3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19413,7 +19413,7 @@ medusa-interfaces@^1.3.7, medusa-interfaces@1.x: integrity sha512-vU1PjepGeglUmEqoBY72gx5Pfj5Uv3VCO3oqYpj6hSz55jhy4xnUNhf4Ttw1mhqGmwtyi9UkHx+aTuCcYx24Ww== "medusa-plugin-strapi-ts@file:/home/ec2-user/hercules/public-plugins/medusa-strapi-repo/packages/medusa-plugin-strapi-ts": - version "5.0.16" + version "5.0.17" resolved "file:packages/medusa-plugin-strapi-ts" dependencies: "@types/bcrypt" "^5.0.0"