UNPKG

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