Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Feb 24, 2024
1 parent 9dbc2b7 commit 51b1151
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ async function fastifyRateLimit (fastify, settings) {
}, settings.addHeadersOnExceeding)

// Global maximum allowed requests
const maxType = typeof settings.max
if (maxType === 'function') {
if (typeof settings.max === 'function') {
globalParams.max = settings.max
} else if (
maxType === 'number' &&
Number.isFinite(settings.max) && settings.max >= 0
) {
globalParams.max = Math.trunc(settings.max)
Expand All @@ -72,13 +70,11 @@ async function fastifyRateLimit (fastify, settings) {
}

// Global time window
const twType = typeof settings.timeWindow
if (twType === 'function') {
if (typeof settings.timeWindow === 'function') {
globalParams.timeWindow = settings.timeWindow
} else if (twType === 'string') {
} else if (typeof settings.timeWindow === 'string') {
globalParams.timeWindow = ms.parse(settings.timeWindow)
} else if (
twType === 'number' &&
Number.isFinite(settings.timeWindow) && settings.timeWindow >= 0
) {
globalParams.timeWindow = Math.trunc(settings.timeWindow)
Expand Down

0 comments on commit 51b1151

Please sign in to comment.