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