UNPKG

5.36 kBTypeScriptView Raw
1import { CorsOptions, CorsOptionsDelegate } from './external/cors-options.interface';
2import { CanActivate } from './features/can-activate.interface';
3import { NestInterceptor } from './features/nest-interceptor.interface';
4import { GlobalPrefixOptions } from './global-prefix-options.interface';
5import { HttpServer } from './http/http-server.interface';
6import { ExceptionFilter, INestMicroservice, NestHybridApplicationOptions, PipeTransform } from './index';
7import { INestApplicationContext } from './nest-application-context.interface';
8import { VersioningOptions } from './version-options.interface';
9import { WebSocketAdapter } from './websockets/web-socket-adapter.interface';
10/**
11 * Interface defining the core NestApplication object.
12 *
13 * @publicApi
14 */
15export interface INestApplication extends INestApplicationContext {
16 /**
17 * A wrapper function around HTTP adapter method: `adapter.use()`.
18 * Example `app.use(cors())`
19 *
20 * @returns {this}
21 */
22 use(...args: any[]): this;
23 /**
24 * Enables CORS (Cross-Origin Resource Sharing)
25 *
26 * @returns {void}
27 */
28 enableCors(options?: CorsOptions | CorsOptionsDelegate<any>): void;
29 /**
30 * Enables Versioning for the application.
31 * By default, URI-based versioning is used.
32 *
33 * @param {VersioningOptions} options
34 * @returns {this}
35 */
36 enableVersioning(options?: VersioningOptions): this;
37 /**
38 * Starts the application.
39 *
40 * @param {number|string} port
41 * @param {string} [hostname]
42 * @param {Function} [callback] Optional callback
43 * @returns {Promise} A Promise that, when resolved, is a reference to the underlying HttpServer.
44 */
45 listen(port: number | string, callback?: () => void): Promise<any>;
46 listen(port: number | string, hostname: string, callback?: () => void): Promise<any>;
47 /**
48 * Starts the application (can be awaited).
49 * @deprecated use "listen" instead.
50 *
51 * @param {number|string} port
52 * @param {string} [hostname]
53 * @returns {Promise}
54 */
55 listenAsync(port: number | string, hostname?: string): Promise<any>;
56 /**
57 * Returns the url the application is listening at, based on OS and IP version. Returns as an IP value either in IPv6 or IPv4
58 *
59 * @returns {Promise<string>} The IP where the server is listening
60 */
61 getUrl(): Promise<string>;
62 /**
63 * Registers a prefix for every HTTP route path.
64 *
65 * @param {string} prefix The prefix for every HTTP route path (for example `/v1/api`)
66 * @param {GlobalPrefixOptions} options Global prefix options object
67 * @returns {this}
68 */
69 setGlobalPrefix(prefix: string, options?: GlobalPrefixOptions): this;
70 /**
71 * Register Ws Adapter which will be used inside Gateways.
72 * Use when you want to override default `socket.io` library.
73 *
74 * @param {WebSocketAdapter} adapter
75 * @returns {this}
76 */
77 useWebSocketAdapter(adapter: WebSocketAdapter): this;
78 /**
79 * Connects microservice to the NestApplication instance. Transforms application
80 * to a hybrid instance.
81 *
82 * @template {object} T
83 * @param {T} options Microservice options object
84 * @param {NestHybridApplicationOptions} hybridOptions Hybrid options object
85 * @returns {INestMicroservice}
86 */
87 connectMicroservice<T extends object = any>(options: T, hybridOptions?: NestHybridApplicationOptions): INestMicroservice;
88 /**
89 * Returns array of the microservices connected to the NestApplication.
90 *
91 * @returns {INestMicroservice[]}
92 */
93 getMicroservices(): INestMicroservice[];
94 /**
95 * Returns the underlying native HTTP server.
96 *
97 * @returns {*}
98 */
99 getHttpServer(): any;
100 /**
101 * Returns the underlying HTTP adapter.
102 *
103 * @returns {HttpServer}
104 */
105 getHttpAdapter(): HttpServer;
106 /**
107 * Starts all connected microservices asynchronously.
108 *
109 * @returns {Promise}
110 */
111 startAllMicroservices(): Promise<this>;
112 /**
113 * Starts all connected microservices and can be awaited.
114 * @deprecated use "startAllMicroservices" instead.
115 *
116 * @returns {Promise}
117 */
118 startAllMicroservicesAsync(): Promise<this>;
119 /**
120 * Registers exception filters as global filters (will be used within
121 * every HTTP route handler)
122 *
123 * @param {...ExceptionFilter} filters
124 */
125 useGlobalFilters(...filters: ExceptionFilter[]): this;
126 /**
127 * Registers pipes as global pipes (will be used within every HTTP route handler)
128 *
129 * @param {...PipeTransform} pipes
130 */
131 useGlobalPipes(...pipes: PipeTransform<any>[]): this;
132 /**
133 * Registers interceptors as global interceptors (will be used within
134 * every HTTP route handler)
135 *
136 * @param {...NestInterceptor} interceptors
137 */
138 useGlobalInterceptors(...interceptors: NestInterceptor[]): this;
139 /**
140 * Registers guards as global guards (will be used within every HTTP route handler)
141 *
142 * @param {...CanActivate} guards
143 */
144 useGlobalGuards(...guards: CanActivate[]): this;
145 /**
146 * Terminates the application (including NestApplication, Gateways, and each connected
147 * microservice)
148 *
149 * @returns {Promise<void>}
150 */
151 close(): Promise<void>;
152}