UNPKG

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