@nestjs/platform-express 9.0.3 → 9.0.6

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.
@@ -7,6 +7,7 @@ import { ServeStaticOptions } from '../interfaces/serve-static-options.interface
7
7
  declare type VersionedRoute = <TRequest extends Record<string, any> = any, TResponse = any>(req: TRequest, res: TResponse, next: () => void) => any;
8
8
  export declare class ExpressAdapter extends AbstractHttpAdapter {
9
9
  private readonly routerMethodFactory;
10
+ private readonly logger;
10
11
  constructor(instance?: any);
11
12
  reply(response: any, body: any, statusCode?: number): any;
12
13
  status(response: any, statusCode: number): any;
@@ -10,10 +10,13 @@ const cors = require("cors");
10
10
  const express = require("express");
11
11
  const http = require("http");
12
12
  const https = require("https");
13
+ const stream_1 = require("stream");
14
+ const get_body_parser_options_util_1 = require("./utils/get-body-parser-options.util");
13
15
  class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
14
16
  constructor(instance) {
15
17
  super(instance || express());
16
18
  this.routerMethodFactory = new router_method_factory_1.RouterMethodFactory();
19
+ this.logger = new common_1.Logger(ExpressAdapter.name);
17
20
  }
18
21
  reply(response, body, statusCode) {
19
22
  if (statusCode) {
@@ -36,7 +39,13 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
36
39
  streamHeaders.length !== undefined) {
37
40
  response.setHeader('Content-Length', streamHeaders.length);
38
41
  }
39
- return body.getStream().pipe(response);
42
+ return (0, stream_1.pipeline)(body.getStream().once('error', (err) => {
43
+ body.errorHandler(err, response);
44
+ }), response, (err) => {
45
+ if (err) {
46
+ this.logger.error(err.message, err.stack);
47
+ }
48
+ });
40
49
  }
41
50
  return (0, shared_utils_1.isObject)(body) ? response.json(body) : response.send(String(body));
42
51
  }
@@ -123,20 +132,11 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
123
132
  this.httpServer = http.createServer(this.getInstance());
124
133
  }
125
134
  registerParserMiddleware(prefix, rawBody) {
126
- let bodyParserJsonOptions;
127
- if (rawBody === true) {
128
- bodyParserJsonOptions = {
129
- verify: (req, _res, buffer) => {
130
- if (Buffer.isBuffer(buffer)) {
131
- req.rawBody = buffer;
132
- }
133
- return true;
134
- },
135
- };
136
- }
135
+ const bodyParserJsonOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody);
136
+ const bodyParserUrlencodedOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody, { extended: true });
137
137
  const parserMiddleware = {
138
138
  jsonParser: (0, body_parser_1.json)(bodyParserJsonOptions),
139
- urlencodedParser: (0, body_parser_1.urlencoded)({ extended: true }),
139
+ urlencodedParser: (0, body_parser_1.urlencoded)(bodyParserUrlencodedOptions),
140
140
  };
141
141
  Object.keys(parserMiddleware)
142
142
  .filter(parser => !this.isMiddlewareApplied(parser))
@@ -0,0 +1,2 @@
1
+ import type { Options } from 'body-parser';
2
+ export declare function getBodyParserOptions<ParserOptions extends Options>(rawBody: boolean, options?: ParserOptions | undefined): ParserOptions;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBodyParserOptions = void 0;
4
+ const rawBodyParser = (req, _res, buffer) => {
5
+ if (Buffer.isBuffer(buffer)) {
6
+ req.rawBody = buffer;
7
+ }
8
+ return true;
9
+ };
10
+ function getBodyParserOptions(rawBody, options) {
11
+ let parserOptions = options !== null && options !== void 0 ? options : {};
12
+ if (rawBody === true) {
13
+ parserOptions = Object.assign(Object.assign({}, parserOptions), { verify: rawBodyParser });
14
+ }
15
+ return parserOptions;
16
+ }
17
+ exports.getBodyParserOptions = getBodyParserOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-express",
3
- "version": "9.0.3",
3
+ "version": "9.0.6",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -24,8 +24,8 @@
24
24
  "tslib": "2.4.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@nestjs/common": "9.0.3",
28
- "@nestjs/core": "9.0.3"
27
+ "@nestjs/common": "9.0.6",
28
+ "@nestjs/core": "9.0.6"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@nestjs/common": "^9.0.0",