fastify-rate-limit
Advanced tools
Comparing version 5.2.0 to 5.3.0
@@ -9,4 +9,2 @@ 'use strict' | ||
const routeRateAdded = Symbol('fastify-rate-limit.routeRateAdded') | ||
let labels = { | ||
@@ -124,8 +122,2 @@ rateLimit: 'x-ratelimit-limit', | ||
async function buildRouteRate (pluginComponent, params, routeOptions) { | ||
if (routeOptions[routeRateAdded]) { | ||
return | ||
} | ||
routeOptions[routeRateAdded] = true | ||
const after = ms(params.timeWindow, { long: true }) | ||
@@ -132,0 +124,0 @@ |
{ | ||
"name": "fastify-rate-limit", | ||
"version": "5.2.0", | ||
"version": "5.3.0", | ||
"description": "A low overhead rate limiter for your routes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -980,2 +980,63 @@ 'use strict' | ||
test('Allow multiple different rate limiter registrations', t => { | ||
t.plan(20) | ||
const fastify = Fastify() | ||
fastify.register(rateLimit, { | ||
max: 1, | ||
timeWindow: 1000, | ||
whitelist: (req) => { | ||
return req.url !== '/test' | ||
} | ||
}) | ||
fastify.register(rateLimit, { | ||
max: 1, | ||
timeWindow: 1000, | ||
whitelist: (req) => { | ||
return req.url === '/test' | ||
} | ||
}) | ||
fastify.get('/', (req, reply) => { | ||
reply.send('hello!') | ||
}) | ||
fastify.get('/test', (req, reply) => { | ||
reply.send('hello from another route!') | ||
}) | ||
fastify.inject('/', (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 200) | ||
t.strictEqual(res.headers['x-ratelimit-limit'], 1) | ||
t.strictEqual(res.headers['x-ratelimit-remaining'], 0) | ||
fastify.inject('/', (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 429) | ||
t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') | ||
t.strictEqual(res.headers['x-ratelimit-limit'], 1) | ||
t.strictEqual(res.headers['x-ratelimit-remaining'], 0) | ||
t.strictEqual(res.headers['retry-after'], 1000) | ||
}) | ||
}) | ||
fastify.inject('/test', (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 200) | ||
t.strictEqual(res.headers['x-ratelimit-limit'], 1) | ||
t.strictEqual(res.headers['x-ratelimit-remaining'], 0) | ||
fastify.inject('/test', (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 429) | ||
t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') | ||
t.strictEqual(res.headers['x-ratelimit-limit'], 1) | ||
t.strictEqual(res.headers['x-ratelimit-remaining'], 0) | ||
t.strictEqual(res.headers['retry-after'], 1000) | ||
}) | ||
}) | ||
}) | ||
test('With enable IETF draft spec', t => { | ||
@@ -982,0 +1043,0 @@ t.plan(5) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91126
2371