@nestjs/platform-express 8.0.4 → 8.0.8
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 +9 -4
- package/adapters/express-adapter.d.ts +2 -1
- package/adapters/express-adapter.js +60 -6
- package/package.json +5 -5
package/Readme.md
CHANGED
|
@@ -67,8 +67,11 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
67
67
|
|
|
68
68
|
<table style="text-align:center;"><tr><td>
|
|
69
69
|
<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>
|
|
70
|
-
<a href="https://weld.
|
|
71
|
-
<
|
|
70
|
+
<a href="https://weld.app/" target="_blank"><img src="https://nestjs.com/img/weld-logo.svg" width="150" valign="middle" /></a></td>
|
|
71
|
+
<td>
|
|
72
|
+
<a href="https://valor-software.com/" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/valor-software.png" width="170" valign="middle" /></a></td>
|
|
73
|
+
<td>
|
|
74
|
+
<a href="https://intrinsic.ventures/" target="_blank"><img src="https://nestjs.com/img/intrinisic-logo.png" width="210" valign="middle" /></a></td></</tr></table>
|
|
72
75
|
|
|
73
76
|
#### Silver Sponsors
|
|
74
77
|
|
|
@@ -76,8 +79,9 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
76
79
|
<a href="https://neoteric.eu/" target="_blank"><img src="https://nestjs.com/img/neoteric-cut.png" width="120" valign="middle" /></a> </td><td>
|
|
77
80
|
<a href="http://gojob.com" target="_blank"><img src="http://nestjs.com/img/gojob-logo.png" valign="middle" width="100" /></a> </td><td>
|
|
78
81
|
<a href="http://www.leogistics.com" target="_blank"><img src="https://nestjs.com/img/leogistics-logo.jpeg" width="150" valign="middle" /></td><td>
|
|
79
|
-
<a href="http://www.meetdandy.com" target="_blank"><img src="https://nestjs.com/img/dandy-
|
|
80
|
-
<a href="https://www.castlecraft.in" target="_blank"><img src="https://nestjs.com/img/castlecraft-logo.png" width="150" valign="middle" /></td
|
|
82
|
+
<a href="http://www.meetdandy.com" target="_blank"><img src="https://nestjs.com/img/dandy-roles-logo.svg" width="150" valign="middle" /></td><td>
|
|
83
|
+
<a href="https://www.castlecraft.in" target="_blank"><img src="https://nestjs.com/img/castlecraft-logo.png" width="150" valign="middle" /></td>
|
|
84
|
+
<td><a href="https://www.tinystacks.com" target="_blank"><img src="https://nestjs.com/img/tinystacks-logo.png" width="55" valign="middle" /></td></tr></table>
|
|
81
85
|
|
|
82
86
|
#### Sponsors
|
|
83
87
|
|
|
@@ -108,6 +112,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
108
112
|
<td align="center" valign="middle"><a href="https://www.bystored.com/" target="_blank"><img src="https://nestjs.com/img/stored-logo.svg" width="110" valign="middle" /></a></td>
|
|
109
113
|
<td align="center" valign="middle"><a href="https://studyclerk.com/pay-for-research-paper" target="_blank"><img src="https://nestjs.com/img/studyclerk-logo.png" width="125" valign="middle" /></a></td><td align="center" valign="middle"><a href="https://xyndata.com" target="_blank"><img src="https://nestjs.com/img/xyndata-logo.png" width="125" valign="middle" /></a></td></tr><tr>
|
|
110
114
|
<td align="center" valign="middle"><a href="https://www.anonymistic.com/" target="_blank"><img src="https://nestjs.com/img/anonymistic-logo.png" width="125" valign="middle" /></a></td>
|
|
115
|
+
<td align="center" valign="middle"><a href="https://www.naologic.com/" target="_blank"><img src="https://nestjs.com/img/naologic-logo.svg" width="125" valign="middle" /></a></td>
|
|
111
116
|
</tr></table>
|
|
112
117
|
|
|
113
118
|
## Backers
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RequestMethod } from '@nestjs/common';
|
|
2
|
+
import { VersioningOptions, VersionValue } from '@nestjs/common/interfaces';
|
|
2
3
|
import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
3
4
|
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
|
|
4
5
|
import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
|
|
5
6
|
import { ServeStaticOptions } from '../interfaces/serve-static-options.interface';
|
|
6
7
|
export declare class ExpressAdapter extends AbstractHttpAdapter {
|
|
7
|
-
private readonly routerMethodFactory;
|
|
8
8
|
constructor(instance?: any);
|
|
9
9
|
reply(response: any, body: any, statusCode?: number): any;
|
|
10
10
|
status(response: any, statusCode: number): any;
|
|
@@ -32,5 +32,6 @@ export declare class ExpressAdapter extends AbstractHttpAdapter {
|
|
|
32
32
|
registerParserMiddleware(): void;
|
|
33
33
|
setLocal(key: string, value: any): this;
|
|
34
34
|
getType(): string;
|
|
35
|
+
applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): <TRequest extends Record<string, any> = any, TResponse = any>(req: TRequest, res: TResponse, next: () => void) => any;
|
|
35
36
|
private isMiddlewareApplied;
|
|
36
37
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
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");
|
|
5
6
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
7
|
const http_adapter_1 = require("@nestjs/core/adapters/http-adapter");
|
|
7
|
-
const router_method_factory_1 = require("@nestjs/core/helpers/router-method-factory");
|
|
8
8
|
const bodyParser = require("body-parser");
|
|
9
9
|
const cors = require("cors");
|
|
10
10
|
const express = require("express");
|
|
@@ -13,7 +13,6 @@ const https = require("https");
|
|
|
13
13
|
class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
14
14
|
constructor(instance) {
|
|
15
15
|
super(instance || express());
|
|
16
|
-
this.routerMethodFactory = new router_method_factory_1.RouterMethodFactory();
|
|
17
16
|
}
|
|
18
17
|
reply(response, body, statusCode) {
|
|
19
18
|
if (statusCode) {
|
|
@@ -23,7 +22,9 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
23
22
|
return response.send();
|
|
24
23
|
}
|
|
25
24
|
if (body instanceof common_1.StreamableFile) {
|
|
26
|
-
response.
|
|
25
|
+
if (response.getHeader('Content-Type') === undefined) {
|
|
26
|
+
response.setHeader('Content-Type', 'application/octet-stream');
|
|
27
|
+
}
|
|
27
28
|
return body.getStream().pipe(response);
|
|
28
29
|
}
|
|
29
30
|
return shared_utils_1.isObject(body) ? response.json(body) : response.send(String(body));
|
|
@@ -92,9 +93,7 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
92
93
|
return this.use(cors(options));
|
|
93
94
|
}
|
|
94
95
|
createMiddlewareFactory(requestMethod) {
|
|
95
|
-
return this.
|
|
96
|
-
.get(this.instance, requestMethod)
|
|
97
|
-
.bind(this.instance);
|
|
96
|
+
return this.instance.use.bind(this.instance);
|
|
98
97
|
}
|
|
99
98
|
initHttpServer(options) {
|
|
100
99
|
const isHttpsEnabled = options && options.httpsOptions;
|
|
@@ -120,6 +119,61 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
120
119
|
getType() {
|
|
121
120
|
return 'express';
|
|
122
121
|
}
|
|
122
|
+
applyVersionFilter(handler, version, versioningOptions) {
|
|
123
|
+
return (req, res, next) => {
|
|
124
|
+
var _a, _b, _c, _d;
|
|
125
|
+
if (version === interfaces_1.VERSION_NEUTRAL) {
|
|
126
|
+
return handler(req, res, next);
|
|
127
|
+
}
|
|
128
|
+
// URL Versioning is done via the path, so the filter continues forward
|
|
129
|
+
if (versioningOptions.type === common_1.VersioningType.URI) {
|
|
130
|
+
return handler(req, res, next);
|
|
131
|
+
}
|
|
132
|
+
// Media Type (Accept Header) Versioning Handler
|
|
133
|
+
if (versioningOptions.type === common_1.VersioningType.MEDIA_TYPE) {
|
|
134
|
+
const MEDIA_TYPE_HEADER = 'Accept';
|
|
135
|
+
const acceptHeaderValue = ((_a = req.headers) === null || _a === void 0 ? void 0 : _a[MEDIA_TYPE_HEADER]) ||
|
|
136
|
+
((_b = req.headers) === null || _b === void 0 ? void 0 : _b[MEDIA_TYPE_HEADER.toLowerCase()]);
|
|
137
|
+
const acceptHeaderVersionParameter = acceptHeaderValue
|
|
138
|
+
? acceptHeaderValue.split(';')[1]
|
|
139
|
+
: '';
|
|
140
|
+
if (acceptHeaderVersionParameter) {
|
|
141
|
+
const headerVersion = acceptHeaderVersionParameter.split(versioningOptions.key)[1];
|
|
142
|
+
if (Array.isArray(version)) {
|
|
143
|
+
if (version.includes(headerVersion)) {
|
|
144
|
+
return handler(req, res, next);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (shared_utils_1.isString(version)) {
|
|
148
|
+
if (version === headerVersion) {
|
|
149
|
+
return handler(req, res, next);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Header Versioning Handler
|
|
155
|
+
else if (versioningOptions.type === common_1.VersioningType.HEADER) {
|
|
156
|
+
const customHeaderVersionParameter = ((_c = req.headers) === null || _c === void 0 ? void 0 : _c[versioningOptions.header]) ||
|
|
157
|
+
((_d = req.headers) === null || _d === void 0 ? void 0 : _d[versioningOptions.header.toLowerCase()]);
|
|
158
|
+
if (customHeaderVersionParameter) {
|
|
159
|
+
if (Array.isArray(version)) {
|
|
160
|
+
if (version.includes(customHeaderVersionParameter)) {
|
|
161
|
+
return handler(req, res, next);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (shared_utils_1.isString(version)) {
|
|
165
|
+
if (version === customHeaderVersionParameter) {
|
|
166
|
+
return handler(req, res, next);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!next) {
|
|
172
|
+
throw new common_1.InternalServerErrorException('HTTP adapter does not support filtering on version');
|
|
173
|
+
}
|
|
174
|
+
return next();
|
|
175
|
+
};
|
|
176
|
+
}
|
|
123
177
|
isMiddlewareApplied(name) {
|
|
124
178
|
const app = this.getInstance();
|
|
125
179
|
return (!!app._router &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/platform-express",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.8",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"body-parser": "1.19.0",
|
|
21
21
|
"cors": "2.8.5",
|
|
22
22
|
"express": "4.17.1",
|
|
23
|
-
"multer": "1.4.
|
|
24
|
-
"tslib": "2.3.
|
|
23
|
+
"multer": "1.4.3",
|
|
24
|
+
"tslib": "2.3.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@nestjs/common": "8.0.
|
|
28
|
-
"@nestjs/core": "8.0.
|
|
27
|
+
"@nestjs/common": "8.0.8",
|
|
28
|
+
"@nestjs/core": "8.0.8"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@nestjs/common": "^8.0.0",
|