UNPKG

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