diff --git a/packages/rjs-handler/src/RateLimiter.ts b/packages/rjs-handler/src/RateLimiter.ts index 01f75bf..cfe155b 100644 --- a/packages/rjs-handler/src/RateLimiter.ts +++ b/packages/rjs-handler/src/RateLimiter.ts @@ -18,7 +18,8 @@ export class RateLimiter { if (this.limit === 0) return true; const now: number = Date.now(); - const limitData: ILimitData = this.limits.get(clientIdentifier) ?? { + const limitData: ILimitData = this.limits.get(clientIdentifier) + ?? { timePivot: now, previousWindow: null, currentWindow: 0 @@ -27,13 +28,11 @@ export class RateLimiter { const windowSpan: number = this.windowSize * 2; const delta: number = now - limitData.timePivot; if (delta > this.windowSize) { - limitData.previousWindow = limitData.currentWindow; + limitData.timePivot = now; + limitData.previousWindow = (delta <= windowSpan) + ? limitData.currentWindow + : 0; limitData.currentWindow = 0; - - if (delta > windowSpan) { - limitData.timePivot = now; - limitData.previousWindow = 0; - } } limitData.currentWindow += 1; diff --git a/packages/rjs-server/package.json b/packages/rjs-server/package.json index 363481c..6a2a5f7 100644 --- a/packages/rjs-server/package.json +++ b/packages/rjs-server/package.json @@ -1,7 +1,7 @@ { "name": "@rapidjs.org/rjs-server", "version": "0.1.3", - "description": "rJS (pron. ‘rapidJS’) is a web server with virtual plugin-based build capabilities.", + "description": "Core web server utility for rJS.", "author": "Thassilo Martin Schiepanski", "license": "Apache-2.0", "homepage": "https://rapidjs.org", diff --git a/packages/rjs/README.md b/packages/rjs/README.md index 0fce354..467b96a 100644 --- a/packages/rjs/README.md +++ b/packages/rjs/README.md @@ -7,18 +7,15 @@

-   -   -  

rJS (pron. ‘rapidJS’) is a plugin-based build interface, and
- a progressive web server based on virtual build capabilites. + a progressive web server based on virtual build capabilities.

## Install diff --git a/packages/rjs/package.json b/packages/rjs/package.json index d1bf42a..1add491 100644 --- a/packages/rjs/package.json +++ b/packages/rjs/package.json @@ -1,7 +1,7 @@ { "name": "@rapidjs.org/rjs", "version": "0.1.3", - "description": "rJS (pron. ‘rapidJS’) is a plugin-based build interface, and a progressive web server based on virtual build capabilites.", + "description": "rJS (pron. ‘rapidJS’) is a plugin-based build interface, and a progressive web server based on virtual build capabilities.", "author": "Thassilo Martin Schiepanski", "license": "Apache-2.0", "homepage": "https://rapidjs.org",