@tsed/platform-express 6.86.2 → 6.88.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.
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
22
|
exports.PlatformExpress = void 0;
|
|
4
23
|
const common_1 = require("@tsed/common");
|
|
@@ -49,7 +68,7 @@ class PlatformExpress extends common_1.PlatformBuilder {
|
|
|
49
68
|
async loadRoutes() {
|
|
50
69
|
// disable x-powered-by header
|
|
51
70
|
this.injector.settings.get("env") === core_1.Env.PROD && this.app.getApp().disable("x-powered-by");
|
|
52
|
-
this.configureViewsEngine();
|
|
71
|
+
await this.configureViewsEngine();
|
|
53
72
|
await super.loadRoutes();
|
|
54
73
|
// NOT FOUND
|
|
55
74
|
this.app.use((req, res, next) => {
|
|
@@ -62,13 +81,28 @@ class PlatformExpress extends common_1.PlatformBuilder {
|
|
|
62
81
|
!res.headersSent && ((_a = this.injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(err, req.$ctx));
|
|
63
82
|
});
|
|
64
83
|
}
|
|
65
|
-
configureViewsEngine() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
async configureViewsEngine() {
|
|
85
|
+
try {
|
|
86
|
+
const { exists, disabled } = this.settings.get("views") || {};
|
|
87
|
+
if (exists && !disabled) {
|
|
88
|
+
const { PlatformViews } = await Promise.resolve().then(() => __importStar(require("@tsed/platform-views")));
|
|
89
|
+
const platformViews = this.injector.get(PlatformViews);
|
|
90
|
+
const app = this.app.getApp();
|
|
91
|
+
platformViews.getEngines().forEach(({ extension, engine }) => {
|
|
92
|
+
app.engine(extension, engine.render);
|
|
93
|
+
});
|
|
94
|
+
platformViews.viewEngine && this.app.getApp().set("view engine", platformViews.viewEngine);
|
|
95
|
+
platformViews.root && this.app.getApp().set("views", platformViews.root);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
// istanbul ignore next
|
|
100
|
+
this.injector.logger.warn({
|
|
101
|
+
event: "PLATFORM_VIEWS_ERROR",
|
|
102
|
+
message: "Unable to configure the PlatformViews service on your environment.",
|
|
103
|
+
error
|
|
104
|
+
});
|
|
105
|
+
}
|
|
72
106
|
}
|
|
73
107
|
}
|
|
74
108
|
exports.PlatformExpress = PlatformExpress;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../src/components/PlatformExpress.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,yCASsB;AACtB,qCAAqC;AAErC,w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B,aAAa,CAAE,CAAC;gBACvE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;gBAE9B,aAAa,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,EAAE;oBACzD,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBACvC,CAAC,CAAC,CAAC;gBAEH,aAAa,CAAC,UAAU,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;gBAC3F,aAAa,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;aAC1E;SACF;QAAC,OAAO,KAAK,EAAE;YACd,uBAAuB;YACvB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;gBACxB,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;;AAhHH,0CAiHC;AAhHQ,yBAAS,GAAG;IACjB;QACE,OAAO,EAAE,4BAAmB;QAC5B,QAAQ,EAAE,qCAA0B;KACrC;IACD;QACE,OAAO,EAAE,uBAAc;QACvB,QAAQ,EAAE,gCAAqB;KAChC;IACD;QACE,OAAO,EAAE,wBAAe;QACxB,QAAQ,EAAE,iCAAsB;KACjC;IACD;QACE,OAAO,EAAE,yBAAgB;QACzB,QAAQ,EAAE,kCAAuB;KAClC;IACD;QACE,OAAO,EAAE,wBAAe;QACxB,QAAQ,EAAE,iCAAsB;KACjC;CACF,CAAC","sourcesContent":["import {\n createContext,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter\n} from \"@tsed/common\";\nimport {Env, Type} from \"@tsed/core\";\nimport Express from \"express\";\nimport {rawBodyMiddleware} from \"../middlewares/rawBodyMiddleware\";\nimport {\n PlatformExpressApplication,\n PlatformExpressHandler,\n PlatformExpressRequest,\n PlatformExpressResponse,\n PlatformExpressRouter\n} from \"../services\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpress extends PlatformBuilder<Express.Application, Express.Router> {\n static providers = [\n {\n provide: PlatformApplication,\n useClass: PlatformExpressApplication\n },\n {\n provide: PlatformRouter,\n useClass: PlatformExpressRouter\n },\n {\n provide: PlatformHandler,\n useClass: PlatformExpressHandler\n },\n {\n provide: PlatformResponse,\n useClass: PlatformExpressResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformExpressRequest\n }\n ];\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return this.build<PlatformExpress>(PlatformExpress, module, {\n httpsPort: false,\n httpPort: false,\n ...settings,\n disableComponentsScan: true\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}): Promise<PlatformExpress> {\n return this.build<PlatformExpress>(PlatformExpress, module, settings).bootstrap();\n }\n\n protected useRouter(): this {\n this.logger.debug(\"Mount app router\");\n this.app.getApp().use(rawBodyMiddleware);\n this.app.getApp().use(this.app.getRouter());\n\n return this;\n }\n\n protected useContext(): this {\n this.logger.debug(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n\n this.app.getApp().use(async (request: any, response: any, next: any) => {\n await invoke({request, response});\n\n return next();\n });\n\n return this;\n }\n\n protected async loadRoutes(): Promise<void> {\n // disable x-powered-by header\n this.injector.settings.get(\"env\") === Env.PROD && this.app.getApp().disable(\"x-powered-by\");\n\n await this.configureViewsEngine();\n\n await super.loadRoutes();\n\n // NOT FOUND\n this.app.use((req: any, res: any, next: any) => {\n !res.headersSent && this.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound(req.$ctx);\n });\n\n // EXCEPTION FILTERS\n this.app.use((err: any, req: any, res: any, next: any) => {\n !res.headersSent && this.injector.get<PlatformExceptions>(PlatformExceptions)?.catch(err, req.$ctx);\n });\n }\n\n private async configureViewsEngine() {\n try {\n const {exists, disabled} = this.settings.get(\"views\") || {};\n\n if (exists && !disabled) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = this.injector.get<PlatformViews>(PlatformViews)!;\n const app = this.app.getApp();\n\n platformViews.getEngines().forEach(({extension, engine}) => {\n app.engine(extension, engine.render);\n });\n\n platformViews.viewEngine && this.app.getApp().set(\"view engine\", platformViews.viewEngine);\n platformViews.root && this.app.getApp().set(\"views\", platformViews.root);\n }\n } catch (error) {\n // istanbul ignore next\n this.injector.logger.warn({\n event: \"PLATFORM_VIEWS_ERROR\",\n message: \"Unable to configure the PlatformViews service on your environment.\",\n error\n });\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-express",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.88.0",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"tslib": "2.2.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tsed/common": "6.
|
|
50
|
-
"@tsed/core": "6.
|
|
51
|
-
"@tsed/di": "6.
|
|
52
|
-
"@tsed/platform-test-utils": "6.
|
|
49
|
+
"@tsed/common": "6.88.0",
|
|
50
|
+
"@tsed/core": "6.88.0",
|
|
51
|
+
"@tsed/di": "6.88.0",
|
|
52
|
+
"@tsed/platform-test-utils": "6.88.0",
|
|
53
53
|
"@types/body-parser": "1.19.0",
|
|
54
54
|
"@types/compression": "1.7.0",
|
|
55
55
|
"@types/cookie-parser": "1.4.2",
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
"method-override": "3.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@tsed/common": "^6.
|
|
69
|
-
"@tsed/core": "^6.
|
|
70
|
-
"@tsed/di": "^6.
|
|
71
|
-
"@tsed/json-mapper": "^6.
|
|
68
|
+
"@tsed/common": "^6.88.0",
|
|
69
|
+
"@tsed/core": "^6.88.0",
|
|
70
|
+
"@tsed/di": "^6.88.0",
|
|
71
|
+
"@tsed/json-mapper": "^6.88.0",
|
|
72
72
|
"@tsed/logger": ">=6.0.0",
|
|
73
|
-
"@tsed/openspec": "^6.
|
|
74
|
-
"@tsed/schema": "^6.
|
|
73
|
+
"@tsed/openspec": "^6.88.0",
|
|
74
|
+
"@tsed/schema": "^6.88.0",
|
|
75
75
|
"@types/multer": "^1.4.5",
|
|
76
76
|
"body-parser": "1.19.0"
|
|
77
77
|
}
|