UNPKG

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