@nestjs/platform-express 8.4.4 → 9.0.0-next.1
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 +3 -2
- package/adapters/express-adapter.d.ts +6 -4
- package/adapters/express-adapter.js +69 -32
- package/package.json +5 -5
package/Readme.md
CHANGED
|
@@ -72,11 +72,12 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
72
72
|
|
|
73
73
|
<table style="text-align:center;"><tr><td>
|
|
74
74
|
<a href="https://careers.labster.com/departments/platform" target="_blank"><img src="https://nestjs.com/img/labster-logo.png" width="170" valign="middle" /></a></td><td>
|
|
75
|
-
<a href="https://weld.app/" target="_blank"><img src="https://nestjs.com/img/weld-logo.svg" width="
|
|
75
|
+
<a href="https://weld.app/" target="_blank"><img src="https://nestjs.com/img/weld-logo.svg" width="140" valign="middle" /></a></td>
|
|
76
76
|
<td>
|
|
77
77
|
<a href="https://intrinsic.ventures/" target="_blank"><img src="https://nestjs.com/img/intrinisic-logo.png" width="210" valign="middle" /></a></td>
|
|
78
78
|
<td>
|
|
79
|
-
<a href="https://jetbrains.com/" target="_blank"><img src="https://nestjs.com/img/jetbrains-logo.svg" width="110" valign="middle" /></a></td
|
|
79
|
+
<a href="https://jetbrains.com/" target="_blank"><img src="https://nestjs.com/img/jetbrains-logo.svg" width="110" valign="middle" /></a></td><td>
|
|
80
|
+
<a href="https://snyk.co/nestjs" target="_blank"><img src="https://nestjs.com/img/snyk-logo-black.png" width="185" valign="middle" /></a></td></</tr></table>
|
|
80
81
|
|
|
81
82
|
#### Silver Sponsors
|
|
82
83
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { RequestMethod } from '@nestjs/common';
|
|
2
|
-
import {
|
|
1
|
+
import { RequestMethod, VersioningOptions } from '@nestjs/common';
|
|
2
|
+
import { VersionValue } from '@nestjs/common/interfaces';
|
|
3
3
|
import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
4
4
|
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
|
|
5
5
|
import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
|
|
6
6
|
import { ServeStaticOptions } from '../interfaces/serve-static-options.interface';
|
|
7
|
+
declare type VersionedRoute = <TRequest extends Record<string, any> = any, TResponse = any>(req: TRequest, res: TResponse, next: () => void) => any;
|
|
7
8
|
export declare class ExpressAdapter extends AbstractHttpAdapter {
|
|
8
9
|
private readonly routerMethodFactory;
|
|
9
10
|
constructor(instance?: any);
|
|
@@ -30,9 +31,10 @@ export declare class ExpressAdapter extends AbstractHttpAdapter {
|
|
|
30
31
|
enableCors(options: CorsOptions | CorsOptionsDelegate<any>): any;
|
|
31
32
|
createMiddlewareFactory(requestMethod: RequestMethod): (path: string, callback: Function) => any;
|
|
32
33
|
initHttpServer(options: NestApplicationOptions): void;
|
|
33
|
-
registerParserMiddleware(): void;
|
|
34
|
+
registerParserMiddleware(prefix?: string, rawBody?: boolean): void;
|
|
34
35
|
setLocal(key: string, value: any): this;
|
|
35
36
|
getType(): string;
|
|
36
|
-
applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions):
|
|
37
|
+
applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): VersionedRoute;
|
|
37
38
|
private isMiddlewareApplied;
|
|
38
39
|
}
|
|
40
|
+
export {};
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExpressAdapter = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
const interfaces_1 = require("@nestjs/common/interfaces");
|
|
6
5
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
6
|
const http_adapter_1 = require("@nestjs/core/adapters/http-adapter");
|
|
8
7
|
const router_method_factory_1 = require("@nestjs/core/helpers/router-method-factory");
|
|
@@ -117,9 +116,20 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
117
116
|
}
|
|
118
117
|
this.httpServer = http.createServer(this.getInstance());
|
|
119
118
|
}
|
|
120
|
-
registerParserMiddleware() {
|
|
119
|
+
registerParserMiddleware(prefix, rawBody) {
|
|
120
|
+
let bodyParserJsonOptions;
|
|
121
|
+
if (rawBody === true) {
|
|
122
|
+
bodyParserJsonOptions = {
|
|
123
|
+
verify: (req, _res, buffer) => {
|
|
124
|
+
if (Buffer.isBuffer(buffer)) {
|
|
125
|
+
req.rawBody = buffer;
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
121
131
|
const parserMiddleware = {
|
|
122
|
-
jsonParser: (0, body_parser_1.json)(),
|
|
132
|
+
jsonParser: (0, body_parser_1.json)(bodyParserJsonOptions),
|
|
123
133
|
urlencodedParser: (0, body_parser_1.urlencoded)({ extended: true }),
|
|
124
134
|
};
|
|
125
135
|
Object.keys(parserMiddleware)
|
|
@@ -134,24 +144,28 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
134
144
|
return 'express';
|
|
135
145
|
}
|
|
136
146
|
applyVersionFilter(handler, version, versioningOptions) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return handler(req, res, next);
|
|
147
|
+
const callNextHandler = (req, res, next) => {
|
|
148
|
+
if (!next) {
|
|
149
|
+
throw new common_1.InternalServerErrorException('HTTP adapter does not support filtering on version');
|
|
141
150
|
}
|
|
151
|
+
return next();
|
|
152
|
+
};
|
|
153
|
+
if (version === common_1.VERSION_NEUTRAL ||
|
|
142
154
|
// URL Versioning is done via the path, so the filter continues forward
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
155
|
+
versioningOptions.type === common_1.VersioningType.URI) {
|
|
156
|
+
const handlerForNoVersioning = (req, res, next) => handler(req, res, next);
|
|
157
|
+
return handlerForNoVersioning;
|
|
158
|
+
}
|
|
159
|
+
// Custom Extractor Versioning Handler
|
|
160
|
+
if (versioningOptions.type === common_1.VersioningType.CUSTOM) {
|
|
161
|
+
const handlerForCustomVersioning = (req, res, next) => {
|
|
148
162
|
const extractedVersion = versioningOptions.extractor(req);
|
|
149
163
|
if (Array.isArray(version)) {
|
|
150
164
|
if (Array.isArray(extractedVersion) &&
|
|
151
165
|
version.filter(v => extractedVersion.includes(v)).length) {
|
|
152
166
|
return handler(req, res, next);
|
|
153
167
|
}
|
|
154
|
-
|
|
168
|
+
if ((0, shared_utils_1.isString)(extractedVersion) &&
|
|
155
169
|
version.includes(extractedVersion)) {
|
|
156
170
|
return handler(req, res, next);
|
|
157
171
|
}
|
|
@@ -165,21 +179,33 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
165
179
|
extractedVersion.includes(version)) {
|
|
166
180
|
return handler(req, res, next);
|
|
167
181
|
}
|
|
168
|
-
|
|
169
|
-
version === extractedVersion) {
|
|
182
|
+
if ((0, shared_utils_1.isString)(extractedVersion) && version === extractedVersion) {
|
|
170
183
|
return handler(req, res, next);
|
|
171
184
|
}
|
|
172
185
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
186
|
+
return callNextHandler(req, res, next);
|
|
187
|
+
};
|
|
188
|
+
return handlerForCustomVersioning;
|
|
189
|
+
}
|
|
190
|
+
// Media Type (Accept Header) Versioning Handler
|
|
191
|
+
if (versioningOptions.type === common_1.VersioningType.MEDIA_TYPE) {
|
|
192
|
+
const handlerForMediaTypeVersioning = (req, res, next) => {
|
|
193
|
+
var _a, _b;
|
|
176
194
|
const MEDIA_TYPE_HEADER = 'Accept';
|
|
177
195
|
const acceptHeaderValue = ((_a = req.headers) === null || _a === void 0 ? void 0 : _a[MEDIA_TYPE_HEADER]) ||
|
|
178
196
|
((_b = req.headers) === null || _b === void 0 ? void 0 : _b[MEDIA_TYPE_HEADER.toLowerCase()]);
|
|
179
197
|
const acceptHeaderVersionParameter = acceptHeaderValue
|
|
180
198
|
? acceptHeaderValue.split(';')[1]
|
|
181
|
-
:
|
|
182
|
-
|
|
199
|
+
: undefined;
|
|
200
|
+
// No version was supplied
|
|
201
|
+
if ((0, shared_utils_1.isUndefined)(acceptHeaderVersionParameter)) {
|
|
202
|
+
if (Array.isArray(version)) {
|
|
203
|
+
if (version.includes(common_1.VERSION_NEUTRAL)) {
|
|
204
|
+
return handler(req, res, next);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
183
209
|
const headerVersion = acceptHeaderVersionParameter.split(versioningOptions.key)[1];
|
|
184
210
|
if (Array.isArray(version)) {
|
|
185
211
|
if (version.includes(headerVersion)) {
|
|
@@ -192,12 +218,25 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
192
218
|
}
|
|
193
219
|
}
|
|
194
220
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
221
|
+
return callNextHandler(req, res, next);
|
|
222
|
+
};
|
|
223
|
+
return handlerForMediaTypeVersioning;
|
|
224
|
+
}
|
|
225
|
+
// Header Versioning Handler
|
|
226
|
+
if (versioningOptions.type === common_1.VersioningType.HEADER) {
|
|
227
|
+
const handlerForHeaderVersioning = (req, res, next) => {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
const customHeaderVersionParameter = ((_a = req.headers) === null || _a === void 0 ? void 0 : _a[versioningOptions.header]) ||
|
|
230
|
+
((_b = req.headers) === null || _b === void 0 ? void 0 : _b[versioningOptions.header.toLowerCase()]);
|
|
231
|
+
// No version was supplied
|
|
232
|
+
if ((0, shared_utils_1.isUndefined)(customHeaderVersionParameter)) {
|
|
233
|
+
if (Array.isArray(version)) {
|
|
234
|
+
if (version.includes(common_1.VERSION_NEUTRAL)) {
|
|
235
|
+
return handler(req, res, next);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
201
240
|
if (Array.isArray(version)) {
|
|
202
241
|
if (version.includes(customHeaderVersionParameter)) {
|
|
203
242
|
return handler(req, res, next);
|
|
@@ -209,12 +248,10 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
209
248
|
}
|
|
210
249
|
}
|
|
211
250
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return next();
|
|
217
|
-
};
|
|
251
|
+
return callNextHandler(req, res, next);
|
|
252
|
+
};
|
|
253
|
+
return handlerForHeaderVersioning;
|
|
254
|
+
}
|
|
218
255
|
}
|
|
219
256
|
isMiddlewareApplied(name) {
|
|
220
257
|
const app = this.getInstance();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/platform-express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-next.1",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"body-parser": "1.20.0",
|
|
21
21
|
"cors": "2.8.5",
|
|
22
|
-
"express": "4.
|
|
22
|
+
"express": "4.18.1",
|
|
23
23
|
"multer": "1.4.4",
|
|
24
|
-
"tslib": "2.
|
|
24
|
+
"tslib": "2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@nestjs/common": "
|
|
28
|
-
"@nestjs/core": "
|
|
27
|
+
"@nestjs/common": "^9.0.0-next.1",
|
|
28
|
+
"@nestjs/core": "^9.0.0-next.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@nestjs/common": "^8.0.0",
|