@thzero/library_server_fastify
v0.18.46
Published
An opinionated library of common functionality to bootstrap a Fastify based API application.
Downloads
856
Readme
library_server_fastify
An opinionated library of common functionality to bootstrap a Fastify based API application.
Requirements
NodeJs
Requires NodeJs version 18+.
Installation
Rate Limiting
Rate limiting is provided by @fastify/rate-limit.
Defaults
The following defualts are used.
max: 100, // maximum requests per timeWindow per IP
timeWindow: '1 minute'You can adjust the defaults by overriding the following method in your FastifyBootMain dervived class.
_initRateLimit()Per-Route Overrides
To apply a stricter limit to a specific route, pass a rateLimit config:
router.post(this._join('/logger'), {
config: {
rateLimit: {
max: 30,
timeWindow: '1 minute'
}
}
}, async (request, reply) => { ... });Disabling Rate Limiting Globally
To disable rate limiting for the entire application, override _initRateLimit in your FastifyBootMain derived class and return null:
_initRateLimit(options) {
return null;
}Disabling Rate Limiting on a Route
To opt a route out of rate limiting entirely (e.g. a health check or catch-all):
router.get(this._join('/'), {
config: { rateLimit: false }
}, (request, reply) => {
reply.status(494).send();
});
