@nestjs/platform-express 9.4.2 → 10.0.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/adapters/express-adapter.d.ts +4 -1
- package/adapters/express-adapter.js +6 -8
- package/adapters/utils/get-body-parser-options.util.js +4 -1
- package/interfaces/nest-express-application.interface.d.ts +15 -4
- package/multer/interceptors/any-files.interceptor.js +4 -1
- package/multer/interceptors/file-fields.interceptor.js +4 -1
- package/multer/interceptors/file.interceptor.js +4 -1
- package/multer/interceptors/files.interceptor.js +4 -1
- package/multer/interceptors/index.d.ts +1 -0
- package/multer/interceptors/index.js +1 -0
- package/multer/interceptors/no-files.interceptor.d.ts +3 -0
- package/multer/interceptors/no-files.interceptor.js +37 -0
- package/multer/multer.module.js +2 -3
- package/package.json +6 -6
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { Server } from 'http';
|
|
3
4
|
import { RequestMethod, VersioningOptions } from '@nestjs/common';
|
|
4
5
|
import { VersionValue } from '@nestjs/common/interfaces';
|
|
5
6
|
import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
6
7
|
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
|
|
7
8
|
import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
|
|
9
|
+
import * as http from 'http';
|
|
10
|
+
import * as https from 'https';
|
|
8
11
|
import { NestExpressBodyParserOptions } from '../interfaces/nest-express-body-parser-options.interface';
|
|
9
12
|
import { NestExpressBodyParserType } from '../interfaces/nest-express-body-parser.interface';
|
|
10
13
|
import { ServeStaticOptions } from '../interfaces/serve-static-options.interface';
|
|
@@ -12,7 +15,7 @@ type VersionedRoute = <TRequest extends Record<string, any> = any, TResponse = a
|
|
|
12
15
|
/**
|
|
13
16
|
* @publicApi
|
|
14
17
|
*/
|
|
15
|
-
export declare class ExpressAdapter extends AbstractHttpAdapter {
|
|
18
|
+
export declare class ExpressAdapter extends AbstractHttpAdapter<http.Server | https.Server> {
|
|
16
19
|
private readonly routerMethodFactory;
|
|
17
20
|
private readonly logger;
|
|
18
21
|
private readonly openConnections;
|
|
@@ -54,7 +54,7 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
54
54
|
}
|
|
55
55
|
if (response.getHeader('Content-Type') !== undefined &&
|
|
56
56
|
response.getHeader('Content-Type') !== 'application/json' &&
|
|
57
|
-
|
|
57
|
+
body?.statusCode >= common_1.HttpStatus.BAD_REQUEST) {
|
|
58
58
|
this.logger.warn("Content-Type doesn't match Reply body, you might need a custom ExceptionFilter for non-JSON responses");
|
|
59
59
|
response.setHeader('Content-Type', 'application/json');
|
|
60
60
|
}
|
|
@@ -143,7 +143,7 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
143
143
|
else {
|
|
144
144
|
this.httpServer = http.createServer(this.getInstance());
|
|
145
145
|
}
|
|
146
|
-
if (options
|
|
146
|
+
if (options?.forceCloseConnections) {
|
|
147
147
|
this.trackOpenConnections();
|
|
148
148
|
}
|
|
149
149
|
}
|
|
@@ -220,10 +220,9 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
220
220
|
// Media Type (Accept Header) Versioning Handler
|
|
221
221
|
if (versioningOptions.type === common_1.VersioningType.MEDIA_TYPE) {
|
|
222
222
|
const handlerForMediaTypeVersioning = (req, res, next) => {
|
|
223
|
-
var _a, _b;
|
|
224
223
|
const MEDIA_TYPE_HEADER = 'Accept';
|
|
225
|
-
const acceptHeaderValue =
|
|
226
|
-
|
|
224
|
+
const acceptHeaderValue = req.headers?.[MEDIA_TYPE_HEADER] ||
|
|
225
|
+
req.headers?.[MEDIA_TYPE_HEADER.toLowerCase()];
|
|
227
226
|
const acceptHeaderVersionParameter = acceptHeaderValue
|
|
228
227
|
? acceptHeaderValue.split(';')[1]
|
|
229
228
|
: undefined;
|
|
@@ -255,9 +254,8 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
255
254
|
// Header Versioning Handler
|
|
256
255
|
if (versioningOptions.type === common_1.VersioningType.HEADER) {
|
|
257
256
|
const handlerForHeaderVersioning = (req, res, next) => {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
((_b = req.headers) === null || _b === void 0 ? void 0 : _b[versioningOptions.header.toLowerCase()]);
|
|
257
|
+
const customHeaderVersionParameter = req.headers?.[versioningOptions.header] ||
|
|
258
|
+
req.headers?.[versioningOptions.header.toLowerCase()];
|
|
261
259
|
// No version was supplied
|
|
262
260
|
if ((0, shared_utils_1.isUndefined)(customHeaderVersionParameter)) {
|
|
263
261
|
if (Array.isArray(version)) {
|
|
@@ -10,7 +10,10 @@ const rawBodyParser = (req, _res, buffer) => {
|
|
|
10
10
|
function getBodyParserOptions(rawBody, options) {
|
|
11
11
|
let parserOptions = (options || {});
|
|
12
12
|
if (rawBody === true) {
|
|
13
|
-
parserOptions =
|
|
13
|
+
parserOptions = {
|
|
14
|
+
...parserOptions,
|
|
15
|
+
verify: rawBodyParser,
|
|
16
|
+
};
|
|
14
17
|
}
|
|
15
18
|
return parserOptions;
|
|
16
19
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { INestApplication, HttpServer } from '@nestjs/common';
|
|
5
|
+
import type { Server as CoreHttpServer } from 'http';
|
|
6
|
+
import type { Server as CoreHttpsServer } from 'https';
|
|
7
|
+
import type { Server } from 'net';
|
|
8
|
+
import type { Express } from 'express';
|
|
4
9
|
import { NestExpressBodyParserOptions } from './nest-express-body-parser-options.interface';
|
|
5
|
-
import { ServeStaticOptions } from './serve-static-options.interface';
|
|
6
10
|
import { NestExpressBodyParserType } from './nest-express-body-parser.interface';
|
|
11
|
+
import { ServeStaticOptions } from './serve-static-options.interface';
|
|
7
12
|
/**
|
|
8
13
|
* Interface describing methods on NestExpressApplication.
|
|
9
14
|
*
|
|
@@ -11,7 +16,13 @@ import { NestExpressBodyParserType } from './nest-express-body-parser.interface'
|
|
|
11
16
|
*
|
|
12
17
|
* @publicApi
|
|
13
18
|
*/
|
|
14
|
-
export interface NestExpressApplication extends INestApplication {
|
|
19
|
+
export interface NestExpressApplication<TServer extends CoreHttpServer | CoreHttpsServer = CoreHttpServer> extends INestApplication<TServer> {
|
|
20
|
+
/**
|
|
21
|
+
* Returns the underlying HTTP adapter bounded to the Express.js app.
|
|
22
|
+
*
|
|
23
|
+
* @returns {HttpServer}
|
|
24
|
+
*/
|
|
25
|
+
getHttpAdapter(): HttpServer<Express.Request, Express.Response, Express>;
|
|
15
26
|
/**
|
|
16
27
|
* Starts the application.
|
|
17
28
|
*
|
|
@@ -9,7 +9,10 @@ const multer_utils_1 = require("../multer/multer.utils");
|
|
|
9
9
|
function AnyFilesInterceptor(localOptions) {
|
|
10
10
|
let MixinInterceptor = class MixinInterceptor {
|
|
11
11
|
constructor(options = {}) {
|
|
12
|
-
this.multer = multer(
|
|
12
|
+
this.multer = multer({
|
|
13
|
+
...options,
|
|
14
|
+
...localOptions,
|
|
15
|
+
});
|
|
13
16
|
}
|
|
14
17
|
async intercept(context, next) {
|
|
15
18
|
const ctx = context.switchToHttp();
|
|
@@ -9,7 +9,10 @@ const multer_utils_1 = require("../multer/multer.utils");
|
|
|
9
9
|
function FileFieldsInterceptor(uploadFields, localOptions) {
|
|
10
10
|
let MixinInterceptor = class MixinInterceptor {
|
|
11
11
|
constructor(options = {}) {
|
|
12
|
-
this.multer = multer(
|
|
12
|
+
this.multer = multer({
|
|
13
|
+
...options,
|
|
14
|
+
...localOptions,
|
|
15
|
+
});
|
|
13
16
|
}
|
|
14
17
|
async intercept(context, next) {
|
|
15
18
|
const ctx = context.switchToHttp();
|
|
@@ -9,7 +9,10 @@ const multer_utils_1 = require("../multer/multer.utils");
|
|
|
9
9
|
function FileInterceptor(fieldName, localOptions) {
|
|
10
10
|
let MixinInterceptor = class MixinInterceptor {
|
|
11
11
|
constructor(options = {}) {
|
|
12
|
-
this.multer = multer(
|
|
12
|
+
this.multer = multer({
|
|
13
|
+
...options,
|
|
14
|
+
...localOptions,
|
|
15
|
+
});
|
|
13
16
|
}
|
|
14
17
|
async intercept(context, next) {
|
|
15
18
|
const ctx = context.switchToHttp();
|
|
@@ -9,7 +9,10 @@ const multer_utils_1 = require("../multer/multer.utils");
|
|
|
9
9
|
function FilesInterceptor(fieldName, maxCount, localOptions) {
|
|
10
10
|
let MixinInterceptor = class MixinInterceptor {
|
|
11
11
|
constructor(options = {}) {
|
|
12
|
-
this.multer = multer(
|
|
12
|
+
this.multer = multer({
|
|
13
|
+
...options,
|
|
14
|
+
...localOptions,
|
|
15
|
+
});
|
|
13
16
|
}
|
|
14
17
|
async intercept(context, next) {
|
|
15
18
|
const ctx = context.switchToHttp();
|
|
@@ -5,3 +5,4 @@ tslib_1.__exportStar(require("./any-files.interceptor"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./file-fields.interceptor"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./file.interceptor"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./files.interceptor"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./no-files.interceptor"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoFilesInterceptor = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const multer = require("multer");
|
|
7
|
+
const files_constants_1 = require("../files.constants");
|
|
8
|
+
const multer_utils_1 = require("../multer/multer.utils");
|
|
9
|
+
function NoFilesInterceptor(localOptions) {
|
|
10
|
+
let MixinInterceptor = class MixinInterceptor {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.multer = multer({
|
|
13
|
+
...options,
|
|
14
|
+
...localOptions,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async intercept(context, next) {
|
|
18
|
+
const ctx = context.switchToHttp();
|
|
19
|
+
await new Promise((resolve, reject) => this.multer.none()(ctx.getRequest(), ctx.getResponse(), (err) => {
|
|
20
|
+
if (err) {
|
|
21
|
+
const error = (0, multer_utils_1.transformException)(err);
|
|
22
|
+
return reject(error);
|
|
23
|
+
}
|
|
24
|
+
resolve();
|
|
25
|
+
}));
|
|
26
|
+
return next.handle();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
MixinInterceptor = tslib_1.__decorate([
|
|
30
|
+
tslib_1.__param(0, (0, common_1.Optional)()),
|
|
31
|
+
tslib_1.__param(0, (0, common_1.Inject)(files_constants_1.MULTER_MODULE_OPTIONS)),
|
|
32
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
33
|
+
], MixinInterceptor);
|
|
34
|
+
const Interceptor = (0, common_1.mixin)(MixinInterceptor);
|
|
35
|
+
return Interceptor;
|
|
36
|
+
}
|
|
37
|
+
exports.NoFilesInterceptor = NoFilesInterceptor;
|
package/multer/multer.module.js
CHANGED
|
@@ -7,7 +7,7 @@ const common_1 = require("@nestjs/common");
|
|
|
7
7
|
const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
|
|
8
8
|
const files_constants_1 = require("./files.constants");
|
|
9
9
|
const multer_constants_1 = require("./multer.constants");
|
|
10
|
-
let MulterModule = MulterModule_1 = class MulterModule {
|
|
10
|
+
let MulterModule = exports.MulterModule = MulterModule_1 = class MulterModule {
|
|
11
11
|
static register(options = {}) {
|
|
12
12
|
return {
|
|
13
13
|
module: MulterModule_1,
|
|
@@ -62,7 +62,6 @@ let MulterModule = MulterModule_1 = class MulterModule {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
MulterModule = MulterModule_1 = tslib_1.__decorate([
|
|
65
|
+
exports.MulterModule = MulterModule = MulterModule_1 = tslib_1.__decorate([
|
|
66
66
|
(0, common_1.Module)({})
|
|
67
67
|
], MulterModule);
|
|
68
|
-
exports.MulterModule = MulterModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/platform-express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"cors": "2.8.5",
|
|
23
23
|
"express": "4.18.2",
|
|
24
24
|
"multer": "1.4.4-lts.1",
|
|
25
|
-
"tslib": "2.5.
|
|
25
|
+
"tslib": "2.5.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@nestjs/common": "
|
|
29
|
-
"@nestjs/core": "
|
|
28
|
+
"@nestjs/common": "10.0.0",
|
|
29
|
+
"@nestjs/core": "10.0.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@nestjs/common": "^
|
|
33
|
-
"@nestjs/core": "^
|
|
32
|
+
"@nestjs/common": "^10.0.0",
|
|
33
|
+
"@nestjs/core": "^10.0.0"
|
|
34
34
|
}
|
|
35
35
|
}
|