@tsed/platform-http 8.15.4 → 8.16.0-rc.2
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/lib/esm/common/builder/PlatformBuilder.js +5 -46
- package/lib/esm/common/exports.js +1 -0
- package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js +3 -33
- package/lib/types/common/builder/PlatformBuilder.d.ts +1 -1
- package/lib/types/common/exports.d.ts +1 -0
- package/lib/types/common/middlewares/PlatformAcceptMimesMiddleware.d.ts +3 -15
- package/package.json +24 -18
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { colors, configuration, constant, createContainer, destroyInjector, injector, logger, ProviderScope
|
|
3
|
-
import { $asyncAlter, $asyncEmit } from "@tsed/hooks";
|
|
4
|
-
import { getMiddlewaresForHook } from "@tsed/platform-middlewares";
|
|
1
|
+
import "@tsed/platform-accept-mimes";
|
|
2
|
+
import { colors, configuration, constant, createContainer, destroyInjector, injector, logger, ProviderScope } from "@tsed/di";
|
|
3
|
+
import { $alter, $asyncAlter, $asyncEmit } from "@tsed/hooks";
|
|
5
4
|
import { application } from "../fn/application.js";
|
|
6
5
|
import { Platform } from "../services/Platform.js";
|
|
7
6
|
import { PlatformAdapter } from "../services/PlatformAdapter.js";
|
|
@@ -133,9 +132,6 @@ export class PlatformBuilder {
|
|
|
133
132
|
async runLifecycle() {
|
|
134
133
|
// init adapter (Express, Koa, etc...)
|
|
135
134
|
await this.adapter.onInit();
|
|
136
|
-
setLoggerConfiguration();
|
|
137
|
-
// create the middleware mapping to be executed to the expected hook
|
|
138
|
-
await this.mapTokenMiddlewares();
|
|
139
135
|
await this.loadInjector();
|
|
140
136
|
// add the context middleware to the application
|
|
141
137
|
this.log("Mount app context");
|
|
@@ -244,7 +240,8 @@ export class PlatformBuilder {
|
|
|
244
240
|
* @protected
|
|
245
241
|
*/
|
|
246
242
|
loadMiddlewaresFor(hook) {
|
|
247
|
-
|
|
243
|
+
const middlewares = $alter("$alterMiddlewaresForHook", constant("middlewares", []), [hook]);
|
|
244
|
+
return middlewares.forEach(({ use }) => {
|
|
248
245
|
this.app.use(use);
|
|
249
246
|
});
|
|
250
247
|
}
|
|
@@ -269,42 +266,4 @@ export class PlatformBuilder {
|
|
|
269
266
|
logger().info(printRoutes(await $asyncAlter("$logRoutes", routes)));
|
|
270
267
|
}
|
|
271
268
|
}
|
|
272
|
-
async mapTokenMiddlewares() {
|
|
273
|
-
let middlewares = constant("middlewares", []);
|
|
274
|
-
const env = constant("env");
|
|
275
|
-
const defaultHook = "$beforeRoutesInit";
|
|
276
|
-
const promises = middlewares.map(async (middleware) => {
|
|
277
|
-
if (isFunction(middleware)) {
|
|
278
|
-
return {
|
|
279
|
-
env,
|
|
280
|
-
hook: defaultHook,
|
|
281
|
-
use: middleware
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
if (isString(middleware)) {
|
|
285
|
-
middleware = { env, use: middleware, hook: defaultHook };
|
|
286
|
-
}
|
|
287
|
-
let { use, options } = middleware;
|
|
288
|
-
if (isString(use)) {
|
|
289
|
-
if (["text-parser", "raw-parser", "json-parser", "urlencoded-parser"].includes(use)) {
|
|
290
|
-
use = this.adapter.bodyParser(use.replace("-parser", ""), options);
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
const mod = await import(use);
|
|
294
|
-
use = (mod.default || mod)(options);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (isClass(use) && ["$beforeInit", "$onInit", "$afterInit"].includes(middleware.hook)) {
|
|
298
|
-
throw new Error(`Ts.ED Middleware "${nameOf(use)}" middleware cannot be added on ${middleware.hook} hook. Use one of this hooks instead: $beforeRoutesInit, $onRoutesInit, $afterRoutesInit, $beforeListen, $afterListen, $onReady`);
|
|
299
|
-
}
|
|
300
|
-
return {
|
|
301
|
-
env,
|
|
302
|
-
hook: defaultHook,
|
|
303
|
-
...middleware,
|
|
304
|
-
use
|
|
305
|
-
};
|
|
306
|
-
});
|
|
307
|
-
middlewares = await Promise.all(promises);
|
|
308
|
-
configuration().set("middlewares", middlewares.filter((middleware) => middleware.use));
|
|
309
|
-
}
|
|
310
269
|
}
|
|
@@ -1,35 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { uniq } from "@tsed/core";
|
|
3
|
-
import { constant, injectable, ProviderType } from "@tsed/di";
|
|
4
|
-
import { NotAcceptable } from "@tsed/exceptions";
|
|
5
|
-
import { Context } from "@tsed/platform-params";
|
|
1
|
+
import { PlatformAcceptMimesMiddleware as M } from "@tsed/platform-accept-mimes";
|
|
6
2
|
/**
|
|
7
|
-
* @
|
|
8
|
-
* @platform
|
|
3
|
+
* @deprecated Since version 8.16. Use PlatformAcceptMiddleware from @tsed/platform-accept-mimes package
|
|
9
4
|
*/
|
|
10
|
-
export
|
|
11
|
-
constructor() {
|
|
12
|
-
this.acceptMimes = constant("acceptMimes", []);
|
|
13
|
-
}
|
|
14
|
-
$alterEndpointHandlers(handlers, operationRoute) {
|
|
15
|
-
const hasAcceptMimes = operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;
|
|
16
|
-
return {
|
|
17
|
-
...handlers,
|
|
18
|
-
before: [hasAcceptMimes && PlatformAcceptMimesMiddleware, ...handlers.before].filter(Boolean)
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
use(ctx) {
|
|
22
|
-
const { endpoint, request } = ctx;
|
|
23
|
-
const mimes = uniq((endpoint?.get("acceptMimes") || []).concat(this.acceptMimes));
|
|
24
|
-
if (mimes.length && !request.accepts(mimes)) {
|
|
25
|
-
throw new NotAcceptable(mimes.join(", "));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
__decorate([
|
|
30
|
-
__param(0, Context()),
|
|
31
|
-
__metadata("design:type", Function),
|
|
32
|
-
__metadata("design:paramtypes", [Object]),
|
|
33
|
-
__metadata("design:returntype", void 0)
|
|
34
|
-
], PlatformAcceptMimesMiddleware.prototype, "use", null);
|
|
35
|
-
injectable(PlatformAcceptMimesMiddleware).type(ProviderType.MIDDLEWARE).priority(-10);
|
|
5
|
+
export const PlatformAcceptMimesMiddleware = M;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import "@tsed/platform-accept-mimes";
|
|
2
3
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
3
4
|
import { Type } from "@tsed/core";
|
|
4
5
|
import { InjectorService, ProviderOpts, TokenProvider } from "@tsed/di";
|
|
@@ -98,5 +99,4 @@ export declare class PlatformBuilder<App = TsED.Application> {
|
|
|
98
99
|
protected createHttpServers(): void;
|
|
99
100
|
protected listenServers(): Promise<void>;
|
|
100
101
|
protected logRoutes(layers: PlatformLayer[]): Promise<void>;
|
|
101
|
-
protected mapTokenMiddlewares(): Promise<void>;
|
|
102
102
|
}
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context } from "@tsed/platform-params";
|
|
3
|
-
import type { AlterEndpointHandlersArg } from "@tsed/platform-router";
|
|
4
|
-
import type { JsonOperationRoute } from "@tsed/schema";
|
|
1
|
+
import { PlatformAcceptMimesMiddleware as M } from "@tsed/platform-accept-mimes";
|
|
5
2
|
/**
|
|
6
|
-
* @
|
|
7
|
-
* @platform
|
|
3
|
+
* @deprecated Since version 8.16. Use PlatformAcceptMiddleware from @tsed/platform-accept-mimes package
|
|
8
4
|
*/
|
|
9
|
-
export declare
|
|
10
|
-
protected acceptMimes: string[];
|
|
11
|
-
$alterEndpointHandlers(handlers: AlterEndpointHandlersArg, operationRoute: JsonOperationRoute): {
|
|
12
|
-
before: any[];
|
|
13
|
-
endpoint: import("@tsed/schema").JsonMethodStore;
|
|
14
|
-
after: (Function | import("@tsed/core").Type<any>)[];
|
|
15
|
-
};
|
|
16
|
-
use(ctx: Context): void;
|
|
17
|
-
}
|
|
5
|
+
export declare const PlatformAcceptMimesMiddleware: typeof M;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/platform-http",
|
|
3
3
|
"description": "A TypeScript Framework on top of Express",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.16.0-rc.2",
|
|
6
6
|
"source": "./src/common/index.ts",
|
|
7
7
|
"main": "./lib/esm/common/index.js",
|
|
8
8
|
"module": "./lib/esm/common/index.js",
|
|
@@ -70,39 +70,45 @@
|
|
|
70
70
|
}
|
|
71
71
|
],
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@tsed/core": "8.
|
|
74
|
-
"@tsed/di": "8.
|
|
75
|
-
"@tsed/exceptions": "8.
|
|
76
|
-
"@tsed/hooks": "8.
|
|
77
|
-
"@tsed/json-mapper": "8.
|
|
78
|
-
"@tsed/
|
|
79
|
-
"@tsed/
|
|
80
|
-
"@tsed/platform-
|
|
81
|
-
"@tsed/platform-
|
|
82
|
-
"@tsed/platform-
|
|
83
|
-
"@tsed/platform-
|
|
84
|
-
"@tsed/platform-
|
|
85
|
-
"@tsed/
|
|
73
|
+
"@tsed/core": "8.16.0-rc.2",
|
|
74
|
+
"@tsed/di": "8.16.0-rc.2",
|
|
75
|
+
"@tsed/exceptions": "8.16.0-rc.2",
|
|
76
|
+
"@tsed/hooks": "8.16.0-rc.2",
|
|
77
|
+
"@tsed/json-mapper": "8.16.0-rc.2",
|
|
78
|
+
"@tsed/logger": "^8.0.0-rc.1",
|
|
79
|
+
"@tsed/logger-std": "^8.0.0-rc.1",
|
|
80
|
+
"@tsed/platform-accept-mimes": "8.16.0-rc.2",
|
|
81
|
+
"@tsed/platform-exceptions": "8.16.0-rc.2",
|
|
82
|
+
"@tsed/platform-middlewares": "8.16.0-rc.2",
|
|
83
|
+
"@tsed/platform-multer": "8.16.0-rc.2",
|
|
84
|
+
"@tsed/platform-params": "8.16.0-rc.2",
|
|
85
|
+
"@tsed/platform-response-filter": "8.16.0-rc.2",
|
|
86
|
+
"@tsed/platform-router": "8.16.0-rc.2",
|
|
87
|
+
"@tsed/platform-views": "8.16.0-rc.2",
|
|
88
|
+
"@tsed/schema": "8.16.0-rc.2",
|
|
86
89
|
"@types/json-schema": "7.0.15",
|
|
87
90
|
"accepts": "^1.3.8",
|
|
88
91
|
"tslib": "2.7.0",
|
|
89
92
|
"uuid": "10.0.0"
|
|
90
93
|
},
|
|
91
94
|
"devDependencies": {
|
|
92
|
-
"@tsed/barrels": "8.
|
|
93
|
-
"@tsed/engines": "8.
|
|
94
|
-
"@tsed/typescript": "8.
|
|
95
|
+
"@tsed/barrels": "8.16.0-rc.2",
|
|
96
|
+
"@tsed/engines": "8.16.0-rc.2",
|
|
97
|
+
"@tsed/typescript": "8.16.0-rc.2",
|
|
95
98
|
"cross-env": "7.0.3",
|
|
96
99
|
"eslint": "9.12.0",
|
|
97
100
|
"typescript": "5.4.5",
|
|
98
101
|
"vitest": "3.2.4"
|
|
99
102
|
},
|
|
100
103
|
"peerDependencies": {
|
|
101
|
-
"@tsed/logger": ">=
|
|
104
|
+
"@tsed/logger": ">=8.0.0-rc.1"
|
|
102
105
|
},
|
|
103
106
|
"peerDependenciesMeta": {
|
|
104
107
|
"@tsed/logger": {
|
|
105
108
|
"optional": false
|
|
106
109
|
}
|
|
110
|
+
},
|
|
111
|
+
"publishConfig": {
|
|
112
|
+
"tag": "rc"
|
|
107
113
|
}
|
|
108
114
|
}
|