add throttle middleware

Create throttling on middleware to pause requests until a specified time before continuing. (default time 2s)
This commit is contained in:
Rafi Arrafif
2025-08-24 14:02:28 +07:00
parent 7e8b5be6cd
commit 112f5188ed
2 changed files with 6 additions and 14 deletions

View File

@ -0,0 +1,6 @@
import Elysia from "elysia";
export const throttleMiddleware = (delayMs = 2000) => (app: Elysia) =>
app.onRequest(async () => {
await new Promise((resolve) => setTimeout(resolve, delayMs));
});