Options
All
  • Public
  • Public/Protected
  • All
Menu

A server instance, for hooking into various events, decorating requests, and so on.

Hierarchy

  • FastifyInstance
    • Server

Index

Properties

addContentTypeParser: AddContentTypeParser<Server, IncomingMessage>

Add a content type parser

all: RouteShorthandMethod<Server, IncomingMessage, ServerResponse>
defaultTextParser: FastifyBodyParser<string, Server, IncomingMessage, RouteGenericInterface>

Fastify default plain text parser

delete: RouteShorthandMethod<Server, IncomingMessage, ServerResponse>
get: RouteShorthandMethod<Server, IncomingMessage, ServerResponse>
getDefaultJsonParser: getDefaultJsonParser

Fastify default JSON parser

getDefaultRoute: DefaultRoute<IncomingMessage, ServerResponse>
hasContentTypeParser: hasContentTypeParser
head: RouteShorthandMethod<Server, IncomingMessage, ServerResponse>
initialConfig: Readonly<{ bodyLimit?: number; caseSensitive?: boolean; connectionTimeout?: number; disableRequestLogging?: boolean; forceCloseConnections?: boolean; http2?: boolean; http2SessionTimeout?: number; https?: boolean | Readonly<{ allowHTTP1: boolean }>; ignoreTrailingSlash?: boolean; keepAliveTimeout?: number; maxParamLength?: number; onConstructorPoisoning?: ConstructorAction; onProtoPoisoning?: ProtoAction; pluginTimeout?: number; requestIdHeader?: string; requestIdLogLabel?: string }>

Frozen read-only object registering the initial options passed down by the user to the fastify instance

log: FastifyLoggerInstance
options: RouteShorthandMethod<Server, IncomingMessage, ServerResponse>
patch: RouteShorthandMethod<Server, IncomingMessage, ServerResponse>
post: RouteShorthandMethod<Server, IncomingMessage, ServerResponse>
prefix: string
put: RouteShorthandMethod<Server, IncomingMessage, ServerResponse>
register: FastifyRegister<FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance> & PromiseLike<undefined>>
removeAllContentTypeParsers: removeAllContentTypeParsers

Remove all content type parsers, including the default ones

removeContentTypeParser: removeContentTypeParser

Remove an existing content type parser

server: Server
version: string

Methods

  • addHook<RouteGeneric, ContextConfig, Logger>(name: "onRequest", hook: onRequestHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig>(name: "onRequest", hook: onRequestAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • addHook<RouteGeneric, ContextConfig>(name: "preParsing", hook: preParsingHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • addHook<RouteGeneric, ContextConfig>(name: "preParsing", hook: preParsingAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "preValidation", hook: preValidationHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "preValidation", hook: preValidationAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "preHandler", hook: preHandlerHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "preHandler", hook: preHandlerAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<PreSerializationPayload, RouteGeneric, ContextConfig, Logger>(name: "preSerialization", hook: preSerializationHookHandler<PreSerializationPayload, Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<PreSerializationPayload, RouteGeneric, ContextConfig, Logger>(name: "preSerialization", hook: preSerializationAsyncHookHandler<PreSerializationPayload, Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<OnSendPayload, RouteGeneric, ContextConfig, Logger>(name: "onSend", hook: onSendHookHandler<OnSendPayload, Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<OnSendPayload, RouteGeneric, ContextConfig, Logger>(name: "onSend", hook: onSendAsyncHookHandler<OnSendPayload, Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "onResponse", hook: onResponseHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "onResponse", hook: onResponseAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "onTimeout", hook: onTimeoutHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "onTimeout", hook: onTimeoutAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "onError", hook: onErrorHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyError, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "onError", hook: onErrorAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyError, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook<RouteGeneric, ContextConfig, Logger>(name: "onRoute", hook: onRouteHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>): FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>
  • addHook(name: "onRegister", hook: onRegisterHookHandler<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance, FastifyPluginOptions>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • addHook(name: "onReady", hook: onReadyHookHandler<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • addHook(name: "onReady", hook: onReadyAsyncHookHandler): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • addHook(name: "onClose", hook: onCloseHookHandler<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • addHook(name: "onClose", hook: onCloseAsyncHookHandler<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • 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

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onRequest"
    • hook: onRequestHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    Parameters

    • name: "onRequest"
    • hook: onRequestAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • 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

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    Parameters

    • name: "preParsing"
    • hook: preParsingHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    Parameters

    • name: "preParsing"
    • hook: preParsingAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • 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

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "preValidation"
    • hook: preValidationHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "preValidation"
    • hook: preValidationAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • 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

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "preHandler"
    • hook: preHandlerHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "preHandler"
    • hook: preHandlerAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • 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

    • PreSerializationPayload = unknown

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "preSerialization"
    • hook: preSerializationHookHandler<PreSerializationPayload, Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • Type Parameters

    • PreSerializationPayload = unknown

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "preSerialization"
    • hook: preSerializationAsyncHookHandler<PreSerializationPayload, Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • 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

    • OnSendPayload = unknown

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onSend"
    • hook: onSendHookHandler<OnSendPayload, Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • Type Parameters

    • OnSendPayload = unknown

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onSend"
    • hook: onSendAsyncHookHandler<OnSendPayload, Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • 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

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onResponse"
    • hook: onResponseHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onResponse"
    • hook: onResponseAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • 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

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onTimeout"
    • hook: onTimeoutHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onTimeout"
    • hook: onTimeoutAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • 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

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onError"
    • hook: onErrorHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyError, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onError"
    • hook: onErrorAsyncHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyError, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • 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

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • Logger extends FastifyLoggerInstance = FastifyLoggerInstance

    Parameters

    • name: "onRoute"
    • hook: onRouteHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, Logger>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, Logger>

  • 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: "onRegister"
    • hook: onRegisterHookHandler<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance, FastifyPluginOptions>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • 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.

    Parameters

    • name: "onReady"
    • hook: onReadyHookHandler<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • Parameters

    • name: "onReady"
    • hook: onReadyAsyncHookHandler

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • 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.

    Parameters

    • name: "onClose"
    • hook: onCloseHookHandler<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • Parameters

    • name: "onClose"
    • hook: onCloseAsyncHookHandler<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • addSchema(schema: unknown): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Parameters

    • schema: unknown

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • after(): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance> & PromiseLike<undefined>
  • after(afterListener: ((err: Error) => void)): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance> & PromiseLike<undefined>

  • Parameters

    • afterListener: ((err: Error) => void)
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • close(): Promise<undefined>
  • close(closeListener: (() => void)): undefined
  • Returns Promise<undefined>

  • Parameters

    • closeListener: (() => void)
        • (): void
        • Returns void

    Returns undefined

  • decorate<T>(property: string | symbol, value: T extends ((...args: any[]) => any) ? ((this: FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>, ...args: Parameters<T>) => ReturnType<T>) : T, dependencies?: string[]): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Type Parameters

    • T

    Parameters

    • property: string | symbol
    • value: T extends ((...args: any[]) => any) ? ((this: FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>, ...args: Parameters<T>) => ReturnType<T>) : T
    • Optional dependencies: string[]

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • decorateReply<T>(property: string | symbol, value: T extends ((...args: any[]) => any) ? ((this: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>, ...args: Parameters<T>) => ReturnType<T>) : T, dependencies?: string[]): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Type Parameters

    • T

    Parameters

    • property: string | symbol
    • value: T extends ((...args: any[]) => any) ? ((this: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>, ...args: Parameters<T>) => ReturnType<T>) : T
    • Optional dependencies: string[]

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • decorateRequest<T>(property: string | symbol, value: T extends ((...args: any[]) => any) ? ((this: FastifyRequest<RouteGenericInterface, Server, IncomingMessage, unknown, FastifyLoggerInstance>, ...args: Parameters<T>) => ReturnType<T>) : T, dependencies?: string[]): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Type Parameters

    • T

    Parameters

    • property: string | symbol
    • value: T extends ((...args: any[]) => any) ? ((this: FastifyRequest<RouteGenericInterface, Server, IncomingMessage, unknown, FastifyLoggerInstance>, ...args: Parameters<T>) => ReturnType<T>) : T
    • Optional dependencies: string[]

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • errorHandler(error: FastifyError, request: FastifyRequest<RouteGenericInterface, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>): void
  • Fastify default error handler

    Parameters

    • error: FastifyError
    • request: FastifyRequest<RouteGenericInterface, Server, IncomingMessage, unknown, FastifyLoggerInstance>
    • reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>

    Returns void

  • getSchema(schemaId: string): unknown
  • Parameters

    • schemaId: string

    Returns unknown

  • getSchemas(): Record<string, unknown>
  • Returns Record<string, unknown>

  • hasDecorator(decorator: string | symbol): boolean
  • Parameters

    • decorator: string | symbol

    Returns boolean

  • hasReplyDecorator(decorator: string | symbol): boolean
  • Parameters

    • decorator: string | symbol

    Returns boolean

  • hasRequestDecorator(decorator: string | symbol): boolean
  • Parameters

    • decorator: string | symbol

    Returns boolean

  • inject(opts: string | InjectOptions, cb: CallbackFunc): void
  • inject(opts: string | InjectOptions): Promise<Response>
  • inject(): Chain
  • Parameters

    • opts: string | InjectOptions
    • cb: CallbackFunc

    Returns void

  • Parameters

    • opts: string | InjectOptions

    Returns Promise<Response>

  • Returns Chain

  • listen(port: string | number, address: string, backlog: number, callback: ((err: null | Error, address: string) => void)): void
  • listen(port: string | number, address: string, callback: ((err: null | Error, address: string) => void)): void
  • listen(port: string | number, callback: ((err: null | Error, address: string) => void)): void
  • listen(port: string | number, address?: string, backlog?: number): Promise<string>
  • listen(opts: { backlog?: number; host?: string; port: number }, callback: ((err: null | Error, address: string) => void)): void
  • listen(opts: { backlog?: number; host?: string; port: number }): Promise<string>
  • Parameters

    • port: string | number
    • address: string
    • backlog: number
    • callback: ((err: null | Error, address: string) => void)
        • (err: null | Error, address: string): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

  • Parameters

    • port: string | number
    • address: string
    • callback: ((err: null | Error, address: string) => void)
        • (err: null | Error, address: string): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

  • Parameters

    • port: string | number
    • callback: ((err: null | Error, address: string) => void)
        • (err: null | Error, address: string): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

  • Parameters

    • port: string | number
    • Optional address: string
    • Optional backlog: number

    Returns Promise<string>

  • Parameters

    • opts: { backlog?: number; host?: string; port: number }
      • Optional backlog?: number
      • Optional host?: string
      • port: number
    • callback: ((err: null | Error, address: string) => void)
        • (err: null | Error, address: string): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

  • Parameters

    • opts: { backlog?: number; host?: string; port: number }
      • Optional backlog?: number
      • Optional host?: string
      • port: number

    Returns Promise<string>

  • printPlugins(): string
  • Prints the representation of the plugin tree used by avvio, the plugin registration system

    Returns string

  • printRoutes(opts?: PrintRoutesOptions): string
  • Prints the representation of the internal radix tree used by the router

    Parameters

    • Optional opts: PrintRoutesOptions

    Returns string

  • ready(): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance> & PromiseLike<undefined>
  • ready(readyListener: ((err: Error) => void)): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance> & PromiseLike<undefined>

  • Parameters

    • readyListener: ((err: Error) => void)
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • route<RouteGeneric, ContextConfig, SchemaCompiler>(opts: RouteOptions<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, SchemaCompiler, FastifyLoggerInstance>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig = unknown

    • SchemaCompiler = FastifySchema

    Parameters

    • opts: RouteOptions<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, SchemaCompiler, FastifyLoggerInstance>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • routing(req: IncomingMessage, res: ServerResponse): void
  • Parameters

    • req: IncomingMessage
    • res: ServerResponse

    Returns void

  • setDefaultRoute(defaultRoute: DefaultRoute<IncomingMessage, ServerResponse>): void
  • Parameters

    • defaultRoute: DefaultRoute<IncomingMessage, ServerResponse>

    Returns void

  • setErrorHandler<TError, RouteGeneric>(handler: ((this: FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>, error: TError, request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>) => void | Promise<void | RouteGeneric["Reply"]>)): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Set a function that will be called whenever an error happens

    Type Parameters

    • TError extends Error = FastifyError

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    Parameters

    • handler: ((this: FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>, error: TError, request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>) => void | Promise<void | RouteGeneric["Reply"]>)
        • (this: FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>, error: TError, request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>): void | Promise<void | RouteGeneric["Reply"]>
        • Parameters

          • this: FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
          • error: TError
          • request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>
          • reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>

          Returns void | Promise<void | RouteGeneric["Reply"]>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • setNotFoundHandler<RouteGeneric>(handler: ((request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>) => void)): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • setNotFoundHandler<RouteGeneric, ContextConfig>(opts: { preHandler?: preHandlerHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance> | preHandlerHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>[]; preValidation?: preValidationHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance> | preValidationHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>[] }, handler: ((request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>) => void)): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Set the 404 handler

    Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    Parameters

    • handler: ((request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>) => void)
        • (request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>): void
        • Parameters

          • request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>
          • reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>

          Returns void

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • Type Parameters

    • RouteGeneric extends RouteGenericInterface = RouteGenericInterface

    • ContextConfig extends unknown = unknown

    Parameters

    • opts: { preHandler?: preHandlerHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance> | preHandlerHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>[]; preValidation?: preValidationHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance> | preValidationHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>[] }
      • Optional preHandler?: preHandlerHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance> | preHandlerHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>[]
      • Optional preValidation?: preValidationHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance> | preValidationHookHandler<Server, IncomingMessage, ServerResponse, RouteGeneric, ContextConfig, FastifyLoggerInstance>[]
    • handler: ((request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>) => void)
        • (request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>, reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>): void
        • Parameters

          • request: FastifyRequest<RouteGeneric, Server, IncomingMessage, unknown, FastifyLoggerInstance>
          • reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGeneric, unknown>

          Returns void

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • setReplySerializer(replySerializer: ((payload: unknown, statusCode: number) => string)): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Set the reply serializer for all routes.

    Parameters

    • replySerializer: ((payload: unknown, statusCode: number) => string)
        • (payload: unknown, statusCode: number): string
        • Parameters

          • payload: unknown
          • statusCode: number

          Returns string

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • setSchemaController(schemaControllerOpts: FastifySchemaControllerOptions): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Set the schema controller for all routes.

    Parameters

    • schemaControllerOpts: FastifySchemaControllerOptions

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • setSchemaErrorFormatter(errorFormatter: ((errors: FastifySchemaValidationError[], dataVar: string) => Error)): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Parameters

    • errorFormatter: ((errors: FastifySchemaValidationError[], dataVar: string) => Error)
        • (errors: FastifySchemaValidationError[], dataVar: string): Error
        • Parameters

          • errors: FastifySchemaValidationError[]
          • dataVar: string

          Returns Error

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • setSerializerCompiler<T>(schemaCompiler: FastifySerializerCompiler<T>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Set the schema serializer for all routes.

    Type Parameters

    • T = FastifySchema

    Parameters

    • schemaCompiler: FastifySerializerCompiler<T>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

  • setValidatorCompiler<T>(schemaCompiler: FastifySchemaCompiler<T>): FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>
  • Set the schema validator for all routes.

    Type Parameters

    • T = FastifySchema

    Parameters

    • schemaCompiler: FastifySchemaCompiler<T>

    Returns FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance>

Generated using TypeDoc