AugmentedFastifyInstance
Api Code Documentation / Exports / types / AugmentedFastifyInstance
types.AugmentedFastifyInstance
Interface representing an extended fastify instance
Hierarchy
-
FastifyInstance
↳
AugmentedFastifyInstance
Table of contents
Properties
- addContentTypeParser
- all
- authenticate
- childLoggerFactory
- decorate
- decorateReply
- decorateRequest
- defaultTextParser
- delete
- errorHandler
- get
- getDefaultJsonParser
- hasContentTypeParser
- head
- initialConfig
- jwt
- listeningOrigin
- log
- metrics
- multipartErrors
- options
- patch
- pluginName
- post
- prefix
- put
- rateLimit
- register
- removeAllContentTypeParsers
- removeContentTypeParser
- serializerCompiler
- server
- swagger
- swaggerCSP
- validatorCompiler
- version
Methods
- [asyncDispose]
- addConstraintStrategy
- addHook
- addSchema
- addresses
- after
- close
- findRoute
- getDefaultRoute
- getSchema
- getSchemas
- hasConstraintStrategy
- hasDecorator
- hasPlugin
- hasReplyDecorator
- hasRequestDecorator
- hasRoute
- inject
- listen
- parseCookie
- printPlugins
- printRoutes
- ready
- route
- routing
- serializeCookie
- setChildLoggerFactory
- setDefaultRoute
- setErrorHandler
- setGenReqId
- setNotFoundHandler
- setReplySerializer
- setSchemaController
- setSchemaErrorFormatter
- setSerializerCompiler
- setValidatorCompiler
- signCookie
- unsignCookie
- withTypeProvider
Properties
addContentTypeParser
• addContentTypeParser: AddContentTypeParser
<RawServerDefault
, IncomingMessage
, RouteGenericInterface
, FastifySchema
, FastifyTypeProviderDefault
>
Add a content type parser
Inherited from
FastifyInstance.addContentTypeParser
Defined in
node_modules/fastify/types/instance.d.ts:554
all
• all: RouteShorthandMethod
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.all
Defined in
node_modules/fastify/types/instance.d.ts:215
authenticate
• authenticate: any
Defined in
childLoggerFactory
• childLoggerFactory: FastifyChildLoggerFactory
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>
Hook function that is called when creating a child logger instance for each request which allows for modifying or adding child logger bindings and logger options, or returning a completely custom child logger implementation.
Inherited from
FastifyInstance.childLoggerFactory
Defined in
node_modules/fastify/types/instance.d.ts:496
decorate
• decorate: DecorationMethod
<FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>, FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>>
Inherited from
FastifyInstance.decorate
Defined in
node_modules/fastify/types/instance.d.ts:152
decorateReply
• decorateReply: DecorationMethod
<FastifyReply
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, RouteGenericInterface
, unknown
, FastifySchema
, FastifyTypeProviderDefault
, unknown
>, FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>>
Inherited from
FastifyInstance.decorateReply
Defined in
node_modules/fastify/types/instance.d.ts:154
decorateRequest
• decorateRequest: DecorationMethod
<FastifyRequest
<RouteGenericInterface
, RawServerDefault
, IncomingMessage
, FastifySchema
, FastifyTypeProviderDefault
, unknown
, FastifyBaseLogger
, ResolveFastifyRequestType
<FastifyTypeProviderDefault
, FastifySchema
, RouteGenericInterface
>>, FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>>
Inherited from
FastifyInstance.decorateRequest
Defined in
node_modules/fastify/types/instance.d.ts:153
defaultTextParser
• defaultTextParser: FastifyBodyParser
<string
>
Fastify default plain text parser
Inherited from
FastifyInstance.defaultTextParser
Defined in
node_modules/fastify/types/instance.d.ts:571
delete
• delete: RouteShorthandMethod
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.delete
Defined in
node_modules/fastify/types/instance.d.ts:212
errorHandler
• errorHandler: (error
: FastifyError
, request
: FastifyRequest
<RouteGenericInterface
, RawServerDefault
, IncomingMessage
, FastifySchema
, FastifyTypeProviderDefault
, unknown
, FastifyBaseLogger
, ResolveFastifyRequestType
<FastifyTypeProviderDefault
, FastifySchema
, RouteGenericInterface
>>, reply
: FastifyReply
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, RouteGenericInterface
, unknown
, FastifySchema
, FastifyTypeProviderDefault
, unknown
>) => void
Type declaration
▸ (error
, request
, reply
): void
Fastify default error handler
Parameters
Name | Type |
---|---|
error | FastifyError |
request | FastifyRequest <RouteGenericInterface , RawServerDefault , IncomingMessage , FastifySchema , FastifyTypeProviderDefault , unknown , FastifyBaseLogger , ResolveFastifyRequestType <FastifyTypeProviderDefault , FastifySchema , RouteGenericInterface >> |
reply | FastifyReply <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGenericInterface , unknown , FastifySchema , FastifyTypeProviderDefault , unknown > |
Returns
void
Inherited from
FastifyInstance.errorHandler
Defined in
node_modules/fastify/types/instance.d.ts:477
get
• get: RouteShorthandMethod
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.get
Defined in
node_modules/fastify/types/instance.d.ts:208
getDefaultJsonParser
• getDefaultJsonParser: getDefaultJsonParser
Fastify default JSON parser
Inherited from
FastifyInstance.getDefaultJsonParser
Defined in
node_modules/fastify/types/instance.d.ts:567
hasContentTypeParser
• hasContentTypeParser: hasContentTypeParser
Inherited from
FastifyInstance.hasContentTypeParser
Defined in
node_modules/fastify/types/instance.d.ts:555
head
• head: RouteShorthandMethod
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.head
Defined in
node_modules/fastify/types/instance.d.ts:209
initialConfig
• initialConfig: Readonly
<{ allowUnsafeRegex?
: boolean
; bodyLimit?
: number
; caseSensitive?
: boolean
; connectionTimeout?
: number
; disableRequestLogging?
: boolean
; forceCloseConnections?
: boolean
; http2?
: boolean
; http2SessionTimeout?
: number
; https?
: boolean
| Readonly
<{ allowHTTP1
: boolean
}> ; ignoreDuplicateSlashes?
: boolean
; ignoreTrailingSlash?
: boolean
; keepAliveTimeout?
: number
; maxParamLength?
: number
; onConstructorPoisoning?
: ConstructorAction
; onProtoPoisoning?
: ProtoAction
; pluginTimeout?
: number
; requestIdHeader?
: string
| false
; requestIdLogLabel?
: string
; useSemicolonDelimiter?
: boolean
}>
Frozen read-only object registering the initial options passed down by the user to the fastify instance
Inherited from
FastifyInstance.initialConfig
Defined in
node_modules/fastify/types/instance.d.ts:586
jwt
• jwt: JWT
Inherited from
FastifyInstance.jwt
Defined in
node_modules/@fastify/jwt/types/jwt.d.ts:17
listeningOrigin
• listeningOrigin: string
Inherited from
FastifyInstance.listeningOrigin
Defined in
node_modules/fastify/types/instance.d.ts:132
log
• log: FastifyBaseLogger
Inherited from
FastifyInstance.log
Defined in
node_modules/fastify/types/instance.d.ts:131
metrics
• metrics: IFastifyMetrics
Metrics interface
Inherited from
FastifyInstance.metrics
Defined in
node_modules/fastify-metrics/dist/index.d.ts:12
multipartErrors
• multipartErrors: MultipartErrors
Inherited from
FastifyInstance.multipartErrors
Defined in
node_modules/@fastify/multipart/types/index.d.ts:34
options
• options: RouteShorthandMethod
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.options
Defined in
node_modules/fastify/types/instance.d.ts:213
patch
• patch: RouteShorthandMethod
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.patch
Defined in
node_modules/fastify/types/instance.d.ts:214
pluginName
• pluginName: string
Inherited from
FastifyInstance.pluginName
Defined in
node_modules/fastify/types/instance.d.ts:128
post
• post: RouteShorthandMethod
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.post
Defined in
node_modules/fastify/types/instance.d.ts:210
prefix
• prefix: string
Inherited from
FastifyInstance.prefix
Defined in
node_modules/fastify/types/instance.d.ts:129
put
• put: RouteShorthandMethod
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.put
Defined in
node_modules/fastify/types/instance.d.ts:211
rateLimit
• rateLimit: (options?
: RateLimitOptions
) => preHandlerAsyncHookHandler
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, RouteGenericInterface
, unknown
, FastifySchema
, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Type declaration
▸ (options?
): preHandlerAsyncHookHandler
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, RouteGenericInterface
, unknown
, FastifySchema
, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Parameters
Name | Type |
---|---|
options? | RateLimitOptions |
Returns
preHandlerAsyncHookHandler
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, RouteGenericInterface
, unknown
, FastifySchema
, FastifyTypeProviderDefault
, FastifyBaseLogger
>
Inherited from
FastifyInstance.rateLimit
Defined in
node_modules/@fastify/rate-limit/types/index.d.ts:12
register
• register: FastifyRegister
<FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
> & PromiseLike
<undefined
>, RawServerDefault
, FastifyTypeProvider
, FastifyBaseLogger
>
Inherited from
FastifyInstance.register
Defined in
node_modules/fastify/types/instance.d.ts:196
removeAllContentTypeParsers
• removeAllContentTypeParsers: removeAllContentTypeParsers
Remove all content type parsers, including the default ones
Inherited from
FastifyInstance.removeAllContentTypeParsers
Defined in
node_modules/fastify/types/instance.d.ts:563
removeContentTypeParser
• removeContentTypeParser: removeContentTypeParser
Remove an existing content type parser
Inherited from
FastifyInstance.removeContentTypeParser
Defined in
node_modules/fastify/types/instance.d.ts:559
serializerCompiler
• serializerCompiler: undefined
| FastifySerializerCompiler
<any
>
Fastify schema serializer for all routes.
Inherited from
FastifyInstance.serializerCompiler
Defined in
node_modules/fastify/types/instance.d.ts:530
server
• server: RawServerDefault
Inherited from
FastifyInstance.server
Defined in
node_modules/fastify/types/instance.d.ts:127
swagger
• swagger: (opts?
: { yaml?
: false
}) => Document
<> & (opts
: { yaml
: true
}) => string
& (opts
: { yaml
: boolean
}) => string
| Document
<>
Inherited from
FastifyInstance.swagger
Defined in
node_modules/@fastify/swagger/index.d.ts:23
swaggerCSP
• swaggerCSP: any
Overrides
FastifyInstance.swaggerCSP
Defined in
validatorCompiler
• validatorCompiler: undefined
| FastifySchemaCompiler
<any
>
Fastify schema validator for all routes.
Inherited from
FastifyInstance.validatorCompiler
Defined in
node_modules/fastify/types/instance.d.ts:520
version
• version: string
Inherited from
FastifyInstance.version
Defined in
node_modules/fastify/types/instance.d.ts:130
Methods
[asyncDispose]
▸ [asyncDispose](): Promise
<undefined
>
Alias for ()
Returns
Promise
<undefined
>
Inherited from
FastifyInstance.[asyncDispose]
Defined in
node_modules/fastify/types/instance.d.ts:149
addConstraintStrategy
▸ addConstraintStrategy(strategy
): void
Parameters
Name | Type |
---|---|
strategy | ConstraintStrategy <V1 , unknown > |
Returns
void
Inherited from
FastifyInstance.addConstraintStrategy
Defined in
node_modules/fastify/types/instance.d.ts:161
addHook
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
onRequest
is the first hook to be executed in the request lifecycle. There was no previous hook, the next hook will be preParsing
.
Notice: in the onRequest
hook, request.body will always be null, because the body parsing happens before the preHandler
hook.
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends onRequestHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | onRequestAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = onRequestHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "onRequest" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? onRequestAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : onRequestHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:237
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
preParsing
is the second hook to be executed in the request lifecycle. The previous hook was onRequest
, the next hook will be preValidation
.
Notice: in the preParsing
hook, request.body will always be null, because the body parsing happens before the preHandler
hook.
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends preParsingHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | preParsingAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = preParsingHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "preParsing" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? preParsingAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : preParsingHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:252
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
preValidation
is the third hook to be executed in the request lifecycle. The previous hook was preParsing
, the next hook will be preHandler
.
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends preValidationHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | preValidationAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = preValidationHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "preValidation" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? preValidationAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : preValidationHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:266
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
preHandler
is the fourth hook to be executed in the request lifecycle. The previous hook was preValidation
, the next hook will be preSerialization
.
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends preHandlerHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | preHandlerAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = preHandlerHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "preHandler" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? preHandlerAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : preHandlerHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:280
▸ addHook<PreSerializationPayload
, RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
preSerialization
is the fifth hook to be executed in the request lifecycle. The previous hook was preHandler
, the next hook will be onSend
.
Note: the hook is NOT called if the payload is a string, a Buffer, a stream or null.
Type parameters
Name | Type |
---|---|
PreSerializationPayload | unknown |
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends preSerializationHookHandler <PreSerializationPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | preSerializationAsyncHookHandler <PreSerializationPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = preSerializationHookHandler <PreSerializationPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "preSerialization" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? preSerializationAsyncHookHandler <PreSerializationPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : preSerializationHookHandler <PreSerializationPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:295
▸ addHook<OnSendPayload
, RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
You can change the payload with the onSend
hook. It is the sixth hook to be executed in the request lifecycle. The previous hook was preSerialization
, the next hook will be onResponse
.
Note: If you change the payload, you may only change it to a string, a Buffer, a stream, or null.
Type parameters
Name | Type |
---|---|
OnSendPayload | unknown |
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends onSendHookHandler <OnSendPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | onSendAsyncHookHandler <OnSendPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = onSendHookHandler <OnSendPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "onSend" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? onSendAsyncHookHandler <OnSendPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : onSendHookHandler <OnSendPayload , RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:311
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
onResponse
is the seventh and last hook in the request hook lifecycle. The previous hook was onSend
, there is no next hook.
The onResponse hook is executed when a response has been sent, so you will not be able to send more data to the client. It can however be useful for sending data to external services, for example to gather statistics.
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends onResponseHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | onResponseAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = onResponseHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "onResponse" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? onResponseAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : onResponseHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:327
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
onTimeout
is useful if you need to monitor the request timed out in your service. (if the connectionTimeout
property is set on the fastify instance)
The onTimeout hook is executed when a request is timed out and the http socket has been hanged up. Therefore you will not be able to send data to the client.
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends onTimeoutHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | onTimeoutAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = onTimeoutHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "onTimeout" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? onTimeoutAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : onTimeoutHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:342
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
onRequestAbort
is useful if you need to monitor the if the client aborts the request (if the request.raw.aborted
property is set to true
).
The onRequestAbort
hook is executed when a client closes the connection before the entire request has been received. Therefore, you will not be able to send data to the client.
Notice: client abort detection is not completely reliable. See: https://github.com/fastify/fastify/blob/main/docs/Guides/Detecting-When-Clients-Abort.md
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends onRequestAbortHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > | onRequestAbortAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > = onRequestAbortHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "onRequestAbort" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? onRequestAbortAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : onRequestAbortHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:358
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
, Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
This hook is useful if you need to do some custom error logging or add some specific header in case of error. It is not intended for changing the error, and calling reply.send will throw an exception. This hook will be executed only after the customErrorHandler has been executed, and only if the customErrorHandler sends an error back to the user (Note that the default customErrorHandler always sends the error back to the user). Notice: unlike the other hooks, pass an error to the done function is not supported.
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Fn | extends onErrorHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , FastifyError , SchemaCompiler , FastifyTypeProviderDefault , Logger > | onErrorAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , FastifyError , SchemaCompiler , FastifyTypeProviderDefault , Logger > = onErrorHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , FastifyError , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Parameters
Name | Type |
---|---|
name | "onError" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? onErrorAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , FastifyError , SchemaCompiler , FastifyTypeProviderDefault , Logger > : onErrorHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , FastifyError , SchemaCompiler , FastifyTypeProviderDefault , Logger > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:375
▸ addHook<RouteGeneric
, ContextConfig
, SchemaCompiler
, Logger
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Triggered when a new route is registered. Listeners are passed a routeOptions object as the sole parameter. The interface is synchronous, and, as such, the listener does not get passed a callback
Type parameters
Name | Type |
---|---|
RouteGeneric | extends RouteGenericInterface = RouteGenericInterface |
ContextConfig | unknown |
SchemaCompiler | extends FastifySchema = FastifySchema |
Logger | extends FastifyBaseLogger = FastifyBaseLogger |
Parameters
Name | Type |
---|---|
name | "onRoute" |
hook | onRouteHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, RouteGeneric , ContextConfig , SchemaCompiler , FastifyTypeProviderDefault , Logger > |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, Logger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:391
▸ addHook(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>
Triggered when a new plugin is registered and a new encapsulation context is created. The hook will be executed before the registered code. This hook can be useful if you are developing a plugin that needs to know when a plugin context is formed, and you want to operate in that specific context. Note: This hook will not be called if a plugin is wrapped inside fastify-plugin.
Parameters
Name | Type |
---|---|
name | "onRegister" |
hook | onRegisterHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault , FastifyPluginOptions > |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:406
▸ addHook<Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>
Triggered when fastify.listen() or fastify.ready() is invoked to start the server. It is useful when plugins need a "ready" event, for example to load data before the server start listening for requests.
Type parameters
Name | Type |
---|---|
Fn | extends onReadyHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > | onReadyAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > = onReadyHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > |
Parameters
Name | Type |
---|---|
name | "onReady" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? onReadyAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > : onReadyHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:414
▸ addHook<Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>
Triggered when fastify.listen() is invoked to start the server. It is useful when plugins need a "onListen" event, for example to run logics after the server start listening for requests.
Type parameters
Name | Type |
---|---|
Fn | extends onListenAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > | onListenHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > = onListenHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > |
Parameters
Name | Type |
---|---|
name | "onListen" |
hook | Fn extends unknown ? Fn extends AsyncFunction ? onListenAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > : onListenHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > : Fn |
Returns
FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>
Inherited from
FastifyInstance.addHook
Defined in
node_modules/fastify/types/instance.d.ts:424
▸ addHook<Fn
>(name
, hook
): FastifyInstance
<RawServerDefault
, IncomingMessage
, ServerResponse
<IncomingMessage
>, FastifyBaseLogger
, FastifyTypeProviderDefault
>
Triggered when fastify.close() is invoked to stop the server. It is useful when plugins need a "shutdown" event, for example to close an open connection to a database.
Type parameters
Name | Type |
---|---|
Fn | extends onCloseHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > | onCloseAsyncHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > = onCloseHookHandler <RawServerDefault , IncomingMessage , ServerResponse <IncomingMessage >, FastifyBaseLogger , FastifyTypeProviderDefault > |