UNPKG

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