@nestjs/platform-express 9.1.5 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -90,7 +90,9 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
90
90
  <a href="https://www.castlecraft.in" target="_blank"><img src="https://nestjs.com/img/castlecraft-logo.png" width="150" valign="middle" /></td>
91
91
  <td><a href="https://www.tinystacks.com" target="_blank"><img src="https://nestjs.com/img/tinystacks-logo.png#1" width="140" valign="middle" /></td>
92
92
  <td><a href="https://n.inc" target="_blank"><img src="https://nestjs.com/img/n-inc-logo.svg" width="120" valign="middle" /></td></tr><tr>
93
- <td><a href="https://bilberrry.com/" target="_blank"><img src="https://nestjs.com/img/bilberrry-logo.svg" width="180" valign="middle" /></td></tr></table>
93
+ <td><a href="https://bilberrry.com/" target="_blank"><img src="https://nestjs.com/img/bilberrry-logo.svg" width="180" valign="middle" /></td>
94
+ <td><a href="https://ipinfo.ai/" target="_blank"><img src="https://nestjs.com/img/ipinfo-logo.png" width="130" valign="middle" /></td></tr>
95
+ </table>
94
96
 
95
97
  #### Sponsors
96
98
 
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ import type { Server } from 'net';
1
3
  import { RequestMethod, VersioningOptions } from '@nestjs/common';
2
4
  import { VersionValue } from '@nestjs/common/interfaces';
3
5
  import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
@@ -8,6 +10,7 @@ declare type VersionedRoute = <TRequest extends Record<string, any> = any, TResp
8
10
  export declare class ExpressAdapter extends AbstractHttpAdapter {
9
11
  private readonly routerMethodFactory;
10
12
  private readonly logger;
13
+ private readonly openConnections;
11
14
  constructor(instance?: any);
12
15
  reply(response: any, body: any, statusCode?: number): any;
13
16
  status(response: any, statusCode: number): any;
@@ -18,8 +21,8 @@ export declare class ExpressAdapter extends AbstractHttpAdapter {
18
21
  setNotFoundHandler(handler: Function, prefix?: string): any;
19
22
  isHeadersSent(response: any): boolean;
20
23
  setHeader(response: any, name: string, value: string): any;
21
- listen(port: string | number, callback?: () => void): any;
22
- listen(port: string | number, hostname: string, callback?: () => void): any;
24
+ listen(port: string | number, callback?: () => void): Server;
25
+ listen(port: string | number, hostname: string, callback?: () => void): Server;
23
26
  close(): Promise<unknown>;
24
27
  set(...args: any[]): any;
25
28
  enable(...args: any[]): any;
@@ -38,6 +41,8 @@ export declare class ExpressAdapter extends AbstractHttpAdapter {
38
41
  setLocal(key: string, value: any): this;
39
42
  getType(): string;
40
43
  applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): VersionedRoute;
44
+ private trackOpenConnections;
45
+ private closeOpenConnections;
41
46
  private isMiddlewareApplied;
42
47
  }
43
48
  export {};
@@ -17,6 +17,7 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
17
17
  super(instance || express());
18
18
  this.routerMethodFactory = new router_method_factory_1.RouterMethodFactory();
19
19
  this.logger = new common_1.Logger(ExpressAdapter.name);
20
+ this.openConnections = new Set();
20
21
  }
21
22
  reply(response, body, statusCode) {
22
23
  if (statusCode) {
@@ -77,6 +78,7 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
77
78
  return this.httpServer.listen(port, ...args);
78
79
  }
79
80
  close() {
81
+ this.closeOpenConnections();
80
82
  if (!this.httpServer) {
81
83
  return undefined;
82
84
  }
@@ -127,9 +129,13 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
127
129
  const isHttpsEnabled = options && options.httpsOptions;
128
130
  if (isHttpsEnabled) {
129
131
  this.httpServer = https.createServer(options.httpsOptions, this.getInstance());
130
- return;
131
132
  }
132
- this.httpServer = http.createServer(this.getInstance());
133
+ else {
134
+ this.httpServer = http.createServer(this.getInstance());
135
+ }
136
+ if (options === null || options === void 0 ? void 0 : options.forceCloseConnections) {
137
+ this.trackOpenConnections();
138
+ }
133
139
  }
134
140
  registerParserMiddleware(prefix, rawBody) {
135
141
  const bodyParserJsonOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody);
@@ -259,6 +265,18 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
259
265
  return handlerForHeaderVersioning;
260
266
  }
261
267
  }
268
+ trackOpenConnections() {
269
+ this.httpServer.on('connection', (socket) => {
270
+ this.openConnections.add(socket);
271
+ socket.on('close', () => this.openConnections.delete(socket));
272
+ });
273
+ }
274
+ closeOpenConnections() {
275
+ for (const socket of this.openConnections) {
276
+ socket.destroy();
277
+ this.openConnections.delete(socket);
278
+ }
279
+ }
262
280
  isMiddlewareApplied(name) {
263
281
  const app = this.getInstance();
264
282
  return (!!app._router &&
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ import { Server } from 'net';
1
3
  import { INestApplication } from '@nestjs/common';
2
4
  import { ServeStaticOptions } from './serve-static-options.interface';
3
5
  /**
@@ -8,6 +10,16 @@ import { ServeStaticOptions } from './serve-static-options.interface';
8
10
  * @publicApi
9
11
  */
10
12
  export interface NestExpressApplication extends INestApplication {
13
+ /**
14
+ * Starts the application.
15
+ *
16
+ * @param {number|string} port
17
+ * @param {string} [hostname]
18
+ * @param {Function} [callback] Optional callback
19
+ * @returns {Promise} A Promise that, when resolved, is a reference to the underlying HttpServer.
20
+ */
21
+ listen(port: number | string, callback?: () => void): Promise<Server>;
22
+ listen(port: number | string, hostname: string, callback?: () => void): Promise<Server>;
11
23
  /**
12
24
  * A wrapper function around native `express.set()` method.
13
25
  *
@@ -1,5 +1,4 @@
1
- import { Type } from '@nestjs/common';
2
- import { ModuleMetadata } from '@nestjs/common/interfaces';
1
+ import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
3
2
  import { MulterOptions } from './multer-options.interface';
4
3
  export declare type MulterModuleOptions = MulterOptions;
5
4
  export interface MulterOptionsFactory {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-express",
3
- "version": "9.1.5",
3
+ "version": "9.2.0",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -21,11 +21,11 @@
21
21
  "cors": "2.8.5",
22
22
  "express": "4.18.2",
23
23
  "multer": "1.4.4-lts.1",
24
- "tslib": "2.4.0"
24
+ "tslib": "2.4.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@nestjs/common": "9.1.5",
28
- "@nestjs/core": "9.1.5"
27
+ "@nestjs/common": "9.2.0",
28
+ "@nestjs/core": "9.2.0"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@nestjs/common": "^9.0.0",