@nestjs/platform-fastify

  • Version 11.1.6
  • Published
  • 60 kB
  • 8 dependencies
  • MIT license

Install

npm i @nestjs/platform-fastify
yarn add @nestjs/platform-fastify
pnpm add @nestjs/platform-fastify

Overview

Nest - modern, fast, powerful node.js web framework (@platform-fastify)

Index

Functions

function RouteConfig

RouteConfig: (config: any) => any;

function RouteConstraints

RouteConstraints: (config: RouteShorthandOptions) => any;

function RouteSchema

RouteSchema: (schema: FastifySchema) => any;

Classes

class FastifyAdapter

class FastifyAdapter<
TServer extends RawServerBase = RawServerDefault,
TRawRequest extends FastifyRawRequest<TServer> = FastifyRawRequest<TServer>,
TRawResponse extends RawReplyDefaultExpression<TServer> = RawReplyDefaultExpression<TServer>,
TRequest extends FastifyRequest<
RequestGenericInterface,
TServer,
TRawRequest
> = FastifyRequest<RequestGenericInterface, TServer, TRawRequest>,
TReply extends FastifyReply<
RouteGenericInterface,
TServer,
TRawRequest,
TRawResponse
> = FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse>,
TInstance extends FastifyInstance<
TServer,
TRawRequest,
TRawResponse
> = FastifyInstance<TServer, TRawRequest, TRawResponse>
> extends AbstractHttpAdapter<TServer, TRequest, TReply> {}

constructor

constructor(instanceOrOptions?: any);

    property instance

    protected readonly instance: FastifyInstance<TServer, TRawRequest, TRawResponse>;

      property isParserRegistered

      readonly isParserRegistered: boolean;

        property logger

        protected readonly logger: Logger;

          method appendHeader

          appendHeader: (response: any, name: string, value: string) => void;

            method applyVersionFilter

            applyVersionFilter: (
            handler: Function,
            version: VersionValue,
            versioningOptions: VersioningOptions
            ) => VersionedRoute<TRequest, TReply>;

              method close

              close: () => Promise<undefined>;

                method copy

                copy: (
                ...args: any[]
                ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                  method createMiddlewareFactory

                  createMiddlewareFactory: (
                  requestMethod: RequestMethod
                  ) => Promise<(path: string, callback: Function) => any>;

                    method delete

                    delete: (
                    ...args: any[]
                    ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                      method enableCors

                      enableCors: (options?: FastifyCorsOptions) => void;

                        method end

                        end: (response: TReply, message?: string) => void;

                          method get

                          get: (
                          ...args: any[]
                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                            method getHeader

                            getHeader: (response: any, name: string) => any;

                              method getHttpServer

                              getHttpServer: <T = TServer>() => T;

                                method getInstance

                                getInstance: <T = TInstance>() => T;

                                  method getRequestHostname

                                  getRequestHostname: (request: TRequest) => string;

                                    method getRequestMethod

                                    getRequestMethod: (request: TRequest) => string;

                                      method getRequestUrl

                                      getRequestUrl: { (request: TRequest): string; (request: TRawRequest): string };

                                        method getType

                                        getType: () => string;

                                          method head

                                          head: (
                                          ...args: any[]
                                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                            method init

                                            init: () => Promise<void>;

                                              method initHttpServer

                                              initHttpServer: () => void;

                                                method inject

                                                inject: {
                                                (): LightMyRequestChain;
                                                (opts: any): Promise<LightMyRequestResponse>;
                                                };

                                                  method isHeadersSent

                                                  isHeadersSent: (response: TReply) => boolean;

                                                    method listen

                                                    listen: {
                                                    (port: string | number, callback?: () => void): void;
                                                    (port: string | number, hostname: string, callback?: () => void): void;
                                                    };

                                                      method lock

                                                      lock: (
                                                      ...args: any[]
                                                      ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                        method mkcol

                                                        mkcol: (
                                                        ...args: any[]
                                                        ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                          method move

                                                          move: (
                                                          ...args: any[]
                                                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                            method options

                                                            options: (
                                                            ...args: any[]
                                                            ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                              method patch

                                                              patch: (
                                                              ...args: any[]
                                                              ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                method post

                                                                post: (
                                                                ...args: any[]
                                                                ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                  method propfind

                                                                  propfind: (
                                                                  ...args: any[]
                                                                  ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                    method proppatch

                                                                    proppatch: (
                                                                    ...args: any[]
                                                                    ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                      method put

                                                                      put: (
                                                                      ...args: any[]
                                                                      ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                        method redirect

                                                                        redirect: (
                                                                        response: TReply,
                                                                        statusCode: number,
                                                                        url: string
                                                                        ) => FastifyReply<
                                                                        RouteGenericInterface,
                                                                        TServer,
                                                                        TRawRequest,
                                                                        TRawResponse,
                                                                        unknown,
                                                                        any,
                                                                        any,
                                                                        unknown
                                                                        >;

                                                                          method register

                                                                          register: <TRegister extends unknown[]>(
                                                                          plugin: TRegister['0'],
                                                                          opts?: TRegister['1']
                                                                          ) => any;

                                                                            method registerParserMiddleware

                                                                            registerParserMiddleware: (prefix?: string, rawBody?: boolean) => void;

                                                                              method registerWithPrefix

                                                                              protected registerWithPrefix: (
                                                                              factory:
                                                                              | FastifyPluginCallback<any>
                                                                              | FastifyPluginAsync<any>
                                                                              | Promise<{ default: FastifyPluginCallback<any> }>
                                                                              | Promise<{ default: FastifyPluginAsync<any> }>,
                                                                              prefix?: string
                                                                              ) => FastifyInstance<
                                                                              TServer,
                                                                              TRawRequest,
                                                                              TRawResponse,
                                                                              FastifyBaseLogger,
                                                                              import('fastify').FastifyTypeProviderDefault
                                                                              > &
                                                                              PromiseLike<undefined> & { __linterBrands: 'SafePromiseLike' };

                                                                                method render

                                                                                render: (
                                                                                response: TReply & { view: Function },
                                                                                view: string,
                                                                                options: any
                                                                                ) => any;

                                                                                  method reply

                                                                                  reply: (
                                                                                  response: TRawResponse | TReply,
                                                                                  body: any,
                                                                                  statusCode?: number
                                                                                  ) => FastifyReply<
                                                                                  RouteGenericInterface,
                                                                                  TServer,
                                                                                  TRawRequest,
                                                                                  TRawResponse,
                                                                                  unknown,
                                                                                  any,
                                                                                  any,
                                                                                  unknown
                                                                                  >;

                                                                                    method search

                                                                                    search: (
                                                                                    ...args: any[]
                                                                                    ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                                      method setErrorHandler

                                                                                      setErrorHandler: (
                                                                                      handler: Parameters<TInstance['setErrorHandler']>[0]
                                                                                      ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                                        method setHeader

                                                                                        setHeader: (
                                                                                        response: TReply,
                                                                                        name: string,
                                                                                        value: string
                                                                                        ) => FastifyReply<
                                                                                        RouteGenericInterface,
                                                                                        TServer,
                                                                                        TRawRequest,
                                                                                        TRawResponse,
                                                                                        unknown,
                                                                                        any,
                                                                                        any,
                                                                                        unknown
                                                                                        >;

                                                                                          method setNotFoundHandler

                                                                                          setNotFoundHandler: (
                                                                                          handler: Function
                                                                                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                                            method setOnRequestHook

                                                                                            setOnRequestHook: (
                                                                                            hook: (
                                                                                            request: TRequest,
                                                                                            reply: TReply,
                                                                                            done: (err?: Error) => void
                                                                                            ) => void | Promise<void>
                                                                                            ) => void;

                                                                                              method setOnResponseHook

                                                                                              setOnResponseHook: (
                                                                                              hook: (
                                                                                              request: TRequest,
                                                                                              reply: TReply,
                                                                                              done: (err?: Error) => void
                                                                                              ) => void | Promise<void>
                                                                                              ) => void;

                                                                                                method setViewEngine

                                                                                                setViewEngine: (options: FastifyViewOptions | string) => any;

                                                                                                  method status

                                                                                                  status: (response: TRawResponse | TReply, statusCode: number) => any;

                                                                                                    method unlock

                                                                                                    unlock: (
                                                                                                    ...args: any[]
                                                                                                    ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                                                      method use

                                                                                                      use: (...args: any[]) => any;

                                                                                                        method useBodyParser

                                                                                                        useBodyParser: (
                                                                                                        type: string | string[] | RegExp,
                                                                                                        rawBody: boolean,
                                                                                                        options?: NestFastifyBodyParserOptions,
                                                                                                        parser?: FastifyBodyParser<Buffer, TServer>
                                                                                                        ) => void;

                                                                                                          method useStaticAssets

                                                                                                          useStaticAssets: (options: FastifyStaticOptions) => any;

                                                                                                            Interfaces

                                                                                                            interface NestFastifyApplication

                                                                                                            interface NestFastifyApplication<TServer extends RawServerBase = RawServerDefault>
                                                                                                            extends INestApplication<TServer> {}

                                                                                                            method enableCors

                                                                                                            enableCors: (options?: FastifyCorsOptions) => void;
                                                                                                            • Enables CORS (Cross-Origin Resource Sharing)

                                                                                                              Returns

                                                                                                              {void}

                                                                                                            method getHttpAdapter

                                                                                                            getHttpAdapter: () => HttpServer<FastifyRequest, FastifyReply, FastifyInstance>;
                                                                                                            • Returns the underlying HTTP adapter bounded to a Fastify app.

                                                                                                              Returns

                                                                                                              {HttpServer}

                                                                                                            method inject

                                                                                                            inject: {
                                                                                                            (): LightMyRequestChain;
                                                                                                            (opts: any): Promise<LightMyRequestResponse>;
                                                                                                            };
                                                                                                            • A wrapper function around native fastify.inject() method.

                                                                                                              Returns

                                                                                                              {void}

                                                                                                            method listen

                                                                                                            listen: {
                                                                                                            (
                                                                                                            opts: FastifyListenOptions,
                                                                                                            callback?: (err: Error | null, address: string) => void
                                                                                                            ): Promise<TServer>;
                                                                                                            (opts?: FastifyListenOptions): Promise<TServer>;
                                                                                                            (callback?: (err: Error, address: string) => void): Promise<TServer>;
                                                                                                            (
                                                                                                            port: string | number,
                                                                                                            callback?: (err: Error, address: string) => void
                                                                                                            ): Promise<TServer>;
                                                                                                            (
                                                                                                            port: string | number,
                                                                                                            address: string,
                                                                                                            callback?: (err: Error, address: string) => void
                                                                                                            ): Promise<TServer>;
                                                                                                            (
                                                                                                            port: string | number,
                                                                                                            address: string,
                                                                                                            backlog: number,
                                                                                                            callback?: (err: Error, address: string) => void
                                                                                                            ): Promise<TServer>;
                                                                                                            };
                                                                                                            • Starts the application.

                                                                                                              Returns

                                                                                                              A Promise that, when resolved, is a reference to the underlying HttpServer.

                                                                                                            method register

                                                                                                            register: <Options extends FastifyPluginOptions = any>(
                                                                                                            plugin:
                                                                                                            | FastifyPluginCallback<Options>
                                                                                                            | FastifyPluginAsync<Options>
                                                                                                            | Promise<{ default: FastifyPluginCallback<Options> }>
                                                                                                            | Promise<{ default: FastifyPluginAsync<Options> }>,
                                                                                                            opts?: FastifyRegisterOptions<Options>
                                                                                                            ) => Promise<FastifyInstance>;
                                                                                                            • A wrapper function around native fastify.register() method. Example `app.register(require('@fastify/formbody'))

                                                                                                              Returns

                                                                                                              {Promise}

                                                                                                            method setViewEngine

                                                                                                            setViewEngine: (options: FastifyViewOptions | string) => this;
                                                                                                            • Sets a view engine for templates (views), for example: pug, handlebars, or ejs.

                                                                                                              Don't pass in a string. The string type in the argument is for compatibility reason and will cause an exception.

                                                                                                              Returns

                                                                                                              {this}

                                                                                                            method useBodyParser

                                                                                                            useBodyParser: <TServer extends RawServerBase = RawServerBase>(
                                                                                                            type: string | string[] | RegExp,
                                                                                                            options?: NestFastifyBodyParserOptions,
                                                                                                            parser?: FastifyBodyParser<Buffer, TServer>
                                                                                                            ) => this;
                                                                                                            • Register Fastify body parsers on the fly. Will respect the application's rawBody option.

                                                                                                              Returns

                                                                                                              {this}

                                                                                                              Example 1

                                                                                                              const app = await NestFactory.create( AppModule, new FastifyAdapter(), { rawBody: true } ); // enable the json parser with a parser limit of 50mb app.useBodyParser('application/json', { bodyLimit: 50 * 1000 * 1024 });

                                                                                                            method useStaticAssets

                                                                                                            useStaticAssets: (options: FastifyStaticOptions) => this;
                                                                                                            • Sets a base directory for public assets. Example app.useStaticAssets({ root: 'public' })

                                                                                                              Returns

                                                                                                              {this}

                                                                                                            Type Aliases

                                                                                                            type NestFastifyBodyParserOptions

                                                                                                            type NestFastifyBodyParserOptions = Omit<
                                                                                                            Parameters<AddContentTypeParser>[1],
                                                                                                            'parseAs'
                                                                                                            >;

                                                                                                              Package Files (7)

                                                                                                              Dependencies (8)

                                                                                                              Dev Dependencies (0)

                                                                                                              No dev dependencies.

                                                                                                              Peer Dependencies (4)

                                                                                                              Badge

                                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@nestjs/platform-fastify.

                                                                                                              • Markdown
                                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@nestjs/platform-fastify)
                                                                                                              • HTML
                                                                                                                <a href="https://www.jsdocs.io/package/@nestjs/platform-fastify"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>