UNPKG

3.02 kBTypeScriptView Raw
1/// <reference types="node" />
2import { INestApplication } from '@nestjs/common';
3import { FastifyBodyParser, FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions, RawServerBase } from 'fastify';
4import { Chain as LightMyRequestChain, InjectOptions, Response as LightMyRequestResponse } from 'light-my-request';
5import { FastifyStaticOptions, FastifyViewOptions } from './external';
6import { NestFastifyBodyParserOptions } from './nest-fastify-body-parser-options.interface';
7/**
8 * @publicApi
9 */
10export interface NestFastifyApplication extends INestApplication {
11 /**
12 * A wrapper function around native `fastify.register()` method.
13 * Example `app.register(require('@fastify/formbody'))
14 * @returns {Promise<FastifyInstance>}
15 */
16 register<Options extends FastifyPluginOptions = any>(plugin: FastifyPluginCallback<Options> | FastifyPluginAsync<Options> | Promise<{
17 default: FastifyPluginCallback<Options>;
18 }> | Promise<{
19 default: FastifyPluginAsync<Options>;
20 }>, opts?: FastifyRegisterOptions<Options>): Promise<FastifyInstance>;
21 /**
22 * Register Fastify body parsers on the fly. Will respect
23 * the application's `rawBody` option.
24 *
25 * @example
26 * const app = await NestFactory.create<NestFastifyApplication>(
27 * AppModule,
28 * new FastifyAdapter(),
29 * { rawBody: true }
30 * );
31 * // enable the json parser with a parser limit of 50mb
32 * app.useBodyParser('application/json', { bodyLimit: 50 * 1000 * 1024 });
33 *
34 * @returns {this}
35 */
36 useBodyParser<TServer extends RawServerBase = RawServerBase>(type: string | string[] | RegExp, options?: NestFastifyBodyParserOptions, parser?: FastifyBodyParser<Buffer, TServer>): this;
37 /**
38 * Sets a base directory for public assets.
39 * Example `app.useStaticAssets({ root: 'public' })`
40 * @returns {this}
41 */
42 useStaticAssets(options: FastifyStaticOptions): this;
43 /**
44 * Sets a view engine for templates (views), for example: `pug`, `handlebars`, or `ejs`.
45 *
46 * Don't pass in a string. The string type in the argument is for compatibilility reason and will cause an exception.
47 * @returns {this}
48 */
49 setViewEngine(options: FastifyViewOptions | string): this;
50 /**
51 * A wrapper function around native `fastify.inject()` method.
52 * @returns {void}
53 */
54 inject(): LightMyRequestChain;
55 inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
56 /**
57 * Starts the application.
58 * @returns A Promise that, when resolved, is a reference to the underlying HttpServer.
59 */
60 listen(port: number | string, callback?: (err: Error, address: string) => void): Promise<any>;
61 listen(port: number | string, address: string, callback?: (err: Error, address: string) => void): Promise<any>;
62 listen(port: number | string, address: string, backlog: number, callback?: (err: Error, address: string) => void): Promise<any>;
63}