Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
/// <reference types='node' />

import {
ContextConfigDefault,
FastifyPluginCallback,
FastifyRequest,
FastifySchema,
preHandlerAsyncHookHandler,
RouteGenericInterface,
RouteOptions
} from 'fastify';

declare module 'fastify' {
interface FastifyInstance {
rateLimit: (options?: fastifyRateLimit.RateLimitOptions) => preHandlerAsyncHookHandler;
interface FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> {
rateLimit<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
>(options?: fastifyRateLimit.RateLimitOptions): preHandlerAsyncHookHandler<
RawServer,
RawRequest,
RawReply,
RouteGeneric,
ContextConfig,
SchemaCompiler,
TypeProvider,
Logger
>;
}
interface FastifyContextConfig {
rateLimit?: fastifyRateLimit.RateLimitOptions | false;
Expand Down
13 changes: 13 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fastify, {
} from 'fastify'
import * as http2 from 'http2'
import { default as ioredis } from 'ioredis'
import pino from 'pino';
import fastifyRateLimit, {
errorResponseBuilderContext,
FastifyRateLimitOptions,
Expand Down Expand Up @@ -160,3 +161,15 @@ const errorResponseContext: errorResponseBuilderContext = {
max: 1000,
ttl: 123
}
const appWithCustomLogger = fastify({
logger: pino(),
}).withTypeProvider()

appWithCustomLogger.register(fastifyRateLimit, options1)

appWithCustomLogger.route({
method: 'GET',
url: '/',
preHandler: appWithCustomLogger.rateLimit({}),
handler: () => {},
})