UNPKG

3.73 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import { INestApplication, HttpServer } from '@nestjs/common';
4import type { Server as CoreHttpServer } from 'http';
5import type { Server as CoreHttpsServer } from 'https';
6import type { Express } from 'express';
7import { NestExpressBodyParserOptions } from './nest-express-body-parser-options.interface';
8import { NestExpressBodyParserType } from './nest-express-body-parser.interface';
9import { ServeStaticOptions } from './serve-static-options.interface';
10/**
11 * Interface describing methods on NestExpressApplication.
12 *
13 * @see [Platform](https://docs.nestjs.com/first-steps#platform)
14 *
15 * @publicApi
16 */
17export interface NestExpressApplication<TServer extends CoreHttpServer | CoreHttpsServer = CoreHttpServer> extends INestApplication<TServer> {
18 /**
19 * Returns the underlying HTTP adapter bounded to the Express.js app.
20 *
21 * @returns {HttpServer}
22 */
23 getHttpAdapter(): HttpServer<Express.Request, Express.Response, Express>;
24 /**
25 * Starts the application.
26 *
27 * @param {number|string} port
28 * @param {string} [hostname]
29 * @param {Function} [callback] Optional callback
30 * @returns {Promise} A Promise that, when resolved, is a reference to the underlying HttpServer.
31 */
32 listen(port: number | string, callback?: () => void): Promise<TServer>;
33 listen(port: number | string, hostname: string, callback?: () => void): Promise<TServer>;
34 /**
35 * A wrapper function around native `express.set()` method.
36 *
37 * @example
38 * app.set('trust proxy', 'loopback')
39 *
40 * @returns {this}
41 */
42 set(...args: any[]): this;
43 /**
44 * A wrapper function around native `express.engine()` method.
45 * @example
46 * app.engine('mustache', mustacheExpress())
47 *
48 * @returns {this}
49 */
50 engine(...args: any[]): this;
51 /**
52 * A wrapper function around native `express.enable()` method.
53 * @example
54 * app.enable('x-powered-by')
55 *
56 * @returns {this}
57 */
58 enable(...args: any[]): this;
59 /**
60 * A wrapper function around native `express.disable()` method.
61 *
62 * @example
63 * app.disable('x-powered-by')
64 *
65 * @returns {this}
66 */
67 disable(...args: any[]): this;
68 useStaticAssets(options: ServeStaticOptions): this;
69 /**
70 * Sets a base directory for public assets.
71 * @example
72 * app.useStaticAssets('public')
73 *
74 * @returns {this}
75 */
76 useStaticAssets(path: string, options?: ServeStaticOptions): this;
77 /**
78 * Register Express body parsers on the fly. Will respect
79 * the application's `rawBody` option.
80 *
81 * @example
82 * const app = await NestFactory.create<NestExpressApplication>(
83 * AppModule,
84 * { rawBody: true }
85 * );
86 * app.useBodyParser('json', { limit: '50mb' });
87 *
88 * @returns {this}
89 */
90 useBodyParser<Options = NestExpressBodyParserOptions>(parser: NestExpressBodyParserType, options?: Omit<Options, 'verify'>): this;
91 /**
92 * Sets one or multiple base directories for templates (views).
93 *
94 * @example
95 * app.setBaseViewsDir('views')
96 *
97 * @returns {this}
98 */
99 setBaseViewsDir(path: string | string[]): this;
100 /**
101 * Sets a view engine for templates (views).
102 * @example
103 * app.setViewEngine('pug')
104 *
105 * @returns {this}
106 */
107 setViewEngine(engine: string): this;
108 /**
109 * Sets app-level globals for view templates.
110 *
111 * @example
112 * app.setLocal('title', 'My Site')
113 *
114 * @see https://expressjs.com/en/4x/api.html#app.locals
115 *
116 * @returns {this}
117 */
118 setLocal(key: string, value: any): this;
119}