@tsed/platform-express 7.0.0-alpha.2 → 7.0.0-beta.11

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.
Files changed (110) hide show
  1. package/lib/cjs/components/PlatformExpress.js +200 -0
  2. package/lib/cjs/components/PlatformExpress.js.map +1 -0
  3. package/lib/{decorators → cjs/decorators}/caseSensitive.js +1 -1
  4. package/lib/cjs/decorators/caseSensitive.js.map +1 -0
  5. package/lib/{decorators → cjs/decorators}/mergeParams.js +1 -1
  6. package/lib/cjs/decorators/mergeParams.js.map +1 -0
  7. package/lib/{decorators → cjs/decorators}/routerSettings.js +1 -1
  8. package/lib/cjs/decorators/routerSettings.js.map +1 -0
  9. package/lib/{decorators → cjs/decorators}/strict.js +1 -1
  10. package/lib/cjs/decorators/strict.js.map +1 -0
  11. package/lib/cjs/exports.js +7 -0
  12. package/lib/cjs/exports.js.map +1 -0
  13. package/lib/cjs/index.js +20 -0
  14. package/lib/cjs/index.js.map +1 -0
  15. package/lib/{interfaces → cjs/interfaces}/PlatformExpressSettings.js +0 -0
  16. package/lib/cjs/interfaces/PlatformExpressSettings.js.map +1 -0
  17. package/lib/{interfaces → cjs/interfaces}/PlatformExpressStaticsOptions.js +0 -0
  18. package/lib/cjs/interfaces/PlatformExpressStaticsOptions.js.map +1 -0
  19. package/lib/cjs/interfaces/interfaces.js +3 -0
  20. package/lib/cjs/interfaces/interfaces.js.map +1 -0
  21. package/lib/{middlewares → cjs/middlewares}/staticsMiddleware.js +0 -0
  22. package/lib/cjs/middlewares/staticsMiddleware.js.map +1 -0
  23. package/lib/cjs/package.json +3 -0
  24. package/lib/{services → cjs/services}/PlatformExpressHandler.js +0 -0
  25. package/lib/cjs/services/PlatformExpressHandler.js.map +1 -0
  26. package/lib/{services → cjs/services}/PlatformExpressRequest.js +0 -0
  27. package/lib/cjs/services/PlatformExpressRequest.js.map +1 -0
  28. package/lib/{services → cjs/services}/PlatformExpressResponse.js +0 -0
  29. package/lib/cjs/services/PlatformExpressResponse.js.map +1 -0
  30. package/lib/esm/components/PlatformExpress.js +196 -0
  31. package/lib/esm/components/PlatformExpress.js.map +1 -0
  32. package/lib/esm/decorators/caseSensitive.js +27 -0
  33. package/lib/esm/decorators/caseSensitive.js.map +1 -0
  34. package/lib/esm/decorators/mergeParams.js +27 -0
  35. package/lib/esm/decorators/mergeParams.js.map +1 -0
  36. package/lib/esm/decorators/routerSettings.js +28 -0
  37. package/lib/esm/decorators/routerSettings.js.map +1 -0
  38. package/lib/esm/decorators/strict.js +27 -0
  39. package/lib/esm/decorators/strict.js.map +1 -0
  40. package/lib/esm/exports.js +5 -0
  41. package/lib/esm/exports.js.map +1 -0
  42. package/lib/esm/index.js +17 -0
  43. package/lib/esm/index.js.map +1 -0
  44. package/lib/esm/interfaces/PlatformExpressSettings.js +2 -0
  45. package/lib/esm/interfaces/PlatformExpressSettings.js.map +1 -0
  46. package/lib/esm/interfaces/PlatformExpressStaticsOptions.js +2 -0
  47. package/lib/esm/interfaces/PlatformExpressStaticsOptions.js.map +1 -0
  48. package/lib/esm/interfaces/interfaces.js +2 -0
  49. package/lib/esm/interfaces/interfaces.js.map +1 -0
  50. package/lib/esm/middlewares/staticsMiddleware.js +16 -0
  51. package/lib/esm/middlewares/staticsMiddleware.js.map +1 -0
  52. package/lib/esm/package.json +3 -0
  53. package/lib/esm/services/PlatformExpressHandler.js +27 -0
  54. package/lib/esm/services/PlatformExpressHandler.js.map +1 -0
  55. package/lib/esm/services/PlatformExpressRequest.js +8 -0
  56. package/lib/esm/services/PlatformExpressRequest.js.map +1 -0
  57. package/lib/esm/services/PlatformExpressResponse.js +8 -0
  58. package/lib/esm/services/PlatformExpressResponse.js.map +1 -0
  59. package/lib/types/components/PlatformExpress.d.ts +75 -0
  60. package/lib/{decorators → types/decorators}/caseSensitive.d.ts +0 -0
  61. package/lib/{decorators → types/decorators}/mergeParams.d.ts +0 -0
  62. package/lib/{decorators → types/decorators}/routerSettings.d.ts +0 -0
  63. package/lib/{decorators → types/decorators}/strict.d.ts +0 -0
  64. package/lib/types/exports.d.ts +1 -0
  65. package/lib/types/index.d.ts +16 -0
  66. package/lib/types/interfaces/PlatformExpressSettings.d.ts +23 -0
  67. package/lib/{interfaces → types/interfaces}/PlatformExpressStaticsOptions.d.ts +0 -0
  68. package/lib/{interfaces/index.d.ts → types/interfaces/interfaces.d.ts} +0 -2
  69. package/lib/{middlewares → types/middlewares}/staticsMiddleware.d.ts +0 -0
  70. package/lib/{services → types/services}/PlatformExpressHandler.d.ts +0 -0
  71. package/lib/types/services/PlatformExpressRequest.d.ts +8 -0
  72. package/lib/{services → types/services}/PlatformExpressResponse.d.ts +0 -0
  73. package/package.json +66 -30
  74. package/readme.md +0 -2
  75. package/tsconfig.compile.esm.json +12 -0
  76. package/lib/components/PlatformExpress.d.ts +0 -28
  77. package/lib/components/PlatformExpress.js +0 -79
  78. package/lib/components/PlatformExpress.js.map +0 -1
  79. package/lib/decorators/caseSensitive.js.map +0 -1
  80. package/lib/decorators/index.d.ts +0 -4
  81. package/lib/decorators/index.js +0 -8
  82. package/lib/decorators/index.js.map +0 -1
  83. package/lib/decorators/mergeParams.js.map +0 -1
  84. package/lib/decorators/routerSettings.js.map +0 -1
  85. package/lib/decorators/strict.js.map +0 -1
  86. package/lib/index.d.ts +0 -4
  87. package/lib/index.js +0 -16
  88. package/lib/index.js.map +0 -1
  89. package/lib/interfaces/PlatformExpressSettings.d.ts +0 -9
  90. package/lib/interfaces/PlatformExpressSettings.js.map +0 -1
  91. package/lib/interfaces/PlatformExpressStaticsOptions.js.map +0 -1
  92. package/lib/interfaces/index.js +0 -6
  93. package/lib/interfaces/index.js.map +0 -1
  94. package/lib/middlewares/rawBodyMiddleware.d.ts +0 -1
  95. package/lib/middlewares/rawBodyMiddleware.js +0 -14
  96. package/lib/middlewares/rawBodyMiddleware.js.map +0 -1
  97. package/lib/middlewares/staticsMiddleware.js.map +0 -1
  98. package/lib/services/PlatformExpressApplication.d.ts +0 -24
  99. package/lib/services/PlatformExpressApplication.js +0 -31
  100. package/lib/services/PlatformExpressApplication.js.map +0 -1
  101. package/lib/services/PlatformExpressHandler.js.map +0 -1
  102. package/lib/services/PlatformExpressRequest.d.ts +0 -22
  103. package/lib/services/PlatformExpressRequest.js.map +0 -1
  104. package/lib/services/PlatformExpressResponse.js.map +0 -1
  105. package/lib/services/PlatformExpressRouter.d.ts +0 -18
  106. package/lib/services/PlatformExpressRouter.js +0 -34
  107. package/lib/services/PlatformExpressRouter.js.map +0 -1
  108. package/lib/services/index.d.ts +0 -5
  109. package/lib/services/index.js +0 -9
  110. package/lib/services/index.js.map +0 -1
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var _PlatformExpress_multer;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PlatformExpress = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const express_1 = tslib_1.__importDefault(require("express"));
7
+ const common_1 = require("@tsed/common");
8
+ const util_1 = require("util");
9
+ const core_1 = require("@tsed/core");
10
+ const PlatformExpressHandler_1 = require("../services/PlatformExpressHandler");
11
+ const PlatformExpressResponse_1 = require("../services/PlatformExpressResponse");
12
+ const PlatformExpressRequest_1 = require("../services/PlatformExpressRequest");
13
+ const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
14
+ /**
15
+ * @platform
16
+ * @express
17
+ */
18
+ class PlatformExpress {
19
+ constructor(injector) {
20
+ this.injector = injector;
21
+ this.providers = [
22
+ {
23
+ provide: common_1.PlatformHandler,
24
+ useClass: PlatformExpressHandler_1.PlatformExpressHandler
25
+ },
26
+ {
27
+ provide: common_1.PlatformResponse,
28
+ useClass: PlatformExpressResponse_1.PlatformExpressResponse
29
+ },
30
+ {
31
+ provide: common_1.PlatformRequest,
32
+ useClass: PlatformExpressRequest_1.PlatformExpressRequest
33
+ }
34
+ ];
35
+ _PlatformExpress_multer.set(this, void 0);
36
+ Promise.resolve().then(() => tslib_1.__importStar(require("multer"))).then(({ default: multer }) => (tslib_1.__classPrivateFieldSet(this, _PlatformExpress_multer, multer, "f")));
37
+ }
38
+ /**
39
+ * Create new serverless application. In this mode, the component scan are disabled.
40
+ * @param module
41
+ * @param settings
42
+ */
43
+ static create(module, settings = {}) {
44
+ return common_1.PlatformBuilder.create(module, {
45
+ ...settings,
46
+ adapter: PlatformExpress
47
+ });
48
+ }
49
+ /**
50
+ * Bootstrap a server application
51
+ * @param module
52
+ * @param settings
53
+ */
54
+ static async bootstrap(module, settings = {}) {
55
+ return common_1.PlatformBuilder.bootstrap(module, {
56
+ ...settings,
57
+ adapter: PlatformExpress
58
+ });
59
+ }
60
+ onInit() {
61
+ this.injector.settings.middlewares = (this.injector.settings.middlewares || []).filter((middleware) => {
62
+ const name = (0, core_1.nameOf)(middleware);
63
+ if (["textParser", "jsonParser", "rawParser", "urlencodedParser"].includes(name)) {
64
+ this.injector.settings.set(`express.bodyParser.${name.replace("Parser", "")}`, () => middleware);
65
+ return false;
66
+ }
67
+ return true;
68
+ });
69
+ }
70
+ useRouter() {
71
+ const { logger } = this.injector;
72
+ const app = this.injector.get(common_1.PlatformApplication);
73
+ logger.debug("Mount app router");
74
+ app.getApp().use(app.getRouter());
75
+ return this;
76
+ }
77
+ async beforeLoadRoutes() {
78
+ const injector = this.injector;
79
+ const app = this.injector.get(common_1.PlatformApplication);
80
+ // disable x-powered-by header
81
+ injector.settings.get("env") === core_1.Env.PROD && app.getApp().disable("x-powered-by");
82
+ await this.configureViewsEngine();
83
+ }
84
+ async afterLoadRoutes() {
85
+ const injector = this.injector;
86
+ const app = this.injector.get(common_1.PlatformApplication);
87
+ // NOT FOUND
88
+ app.use((req, res, next) => {
89
+ var _a;
90
+ !res.headersSent && ((_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.resourceNotFound(req.$ctx));
91
+ });
92
+ // EXCEPTION FILTERS
93
+ app.use((err, req, res, next) => {
94
+ var _a;
95
+ !res.headersSent && ((_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(err, req.$ctx));
96
+ });
97
+ }
98
+ useContext() {
99
+ const { logger } = this.injector;
100
+ logger.debug("Mount app context");
101
+ const invoke = (0, common_1.createContext)(this.injector);
102
+ const app = this.injector.get(common_1.PlatformApplication);
103
+ app.getApp().use(async (request, response, next) => {
104
+ await invoke({ request, response });
105
+ return next();
106
+ });
107
+ return this;
108
+ }
109
+ multipart(options) {
110
+ const m = tslib_1.__classPrivateFieldGet(this, _PlatformExpress_multer, "f").call(this, options);
111
+ const makePromise = (multer, name) => {
112
+ // istanbul ignore next
113
+ if (!multer[name])
114
+ return;
115
+ const fn = multer[name];
116
+ multer[name] = function apply(...args) {
117
+ const middleware = Reflect.apply(fn, this, args);
118
+ return (req, res) => (0, util_1.promisify)(middleware)(req, res);
119
+ };
120
+ };
121
+ makePromise(m, "any");
122
+ makePromise(m, "array");
123
+ makePromise(m, "fields");
124
+ makePromise(m, "none");
125
+ makePromise(m, "single");
126
+ return m;
127
+ }
128
+ app() {
129
+ const app = this.injector.settings.get("express.app") || (0, express_1.default)();
130
+ return {
131
+ app,
132
+ callback() {
133
+ return app;
134
+ }
135
+ };
136
+ }
137
+ router(routerOptions = {}) {
138
+ var _a;
139
+ const options = Object.assign({
140
+ mergeParams: true
141
+ }, ((_a = this.injector.settings.express) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
142
+ const router = express_1.default.Router(options);
143
+ return {
144
+ router,
145
+ callback() {
146
+ return router;
147
+ }
148
+ };
149
+ }
150
+ statics(endpoint, options) {
151
+ const { root, ...props } = options;
152
+ return (0, staticsMiddleware_1.staticsMiddleware)(root, props);
153
+ }
154
+ bodyParser(type, additionalOptions = {}) {
155
+ const opts = this.injector.settings.get(`express.bodyParser.${type}`);
156
+ let parser = express_1.default[type];
157
+ let options = {};
158
+ if ((0, core_1.isFunction)(opts)) {
159
+ parser = opts;
160
+ options = {};
161
+ }
162
+ switch (type) {
163
+ case "urlencoded":
164
+ options.extended = true;
165
+ break;
166
+ case "raw":
167
+ options.type = () => true;
168
+ break;
169
+ }
170
+ return parser({ ...options, ...additionalOptions });
171
+ }
172
+ async configureViewsEngine() {
173
+ const injector = this.injector;
174
+ const app = this.injector.get(common_1.PlatformApplication);
175
+ try {
176
+ const { exists, disabled } = this.injector.settings.get("views") || {};
177
+ if (exists && !disabled) {
178
+ const { PlatformViews } = await Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/platform-views")));
179
+ const platformViews = injector.get(PlatformViews);
180
+ const express = app.getApp();
181
+ platformViews.getEngines().forEach(({ extension, engine }) => {
182
+ express.engine(extension, engine.render);
183
+ });
184
+ platformViews.viewEngine && express.set("view engine", platformViews.viewEngine);
185
+ platformViews.root && express.set("views", platformViews.root);
186
+ }
187
+ }
188
+ catch (error) {
189
+ // istanbul ignore next
190
+ injector.logger.warn({
191
+ event: "PLATFORM_VIEWS_ERROR",
192
+ message: "Unable to configure the PlatformViews service on your environment.",
193
+ error
194
+ });
195
+ }
196
+ }
197
+ }
198
+ exports.PlatformExpress = PlatformExpress;
199
+ _PlatformExpress_multer = new WeakMap();
200
+ //# sourceMappingURL=PlatformExpress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;;AACA,8DAA+C;AAE/C,yCAcsB;AACtB,+BAA+B;AAC/B,qCAAyD;AACzD,+EAA0E;AAC1E,iFAA4E;AAC5E,+EAA0E;AAC1E,wEAAmE;AA0BnE;;;GAGG;AACH,MAAa,eAAe;IAiB1B,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAhBtC,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,+CAAsB;aACjC;YACD;gBACE,OAAO,EAAE,yBAAgB;gBACzB,QAAQ,EAAE,iDAAuB;aAClC;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,+CAA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C,MAAM,CAAC,CAAC;gBAC3C,CAAC,CAAC,CAAC;gBAEH,aAAa,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;gBACjF,aAAa,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;aAChE;SACF;QAAC,OAAO,KAAK,EAAE;YACd,uBAAuB;YACvB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AA3ND,0CA2NC","sourcesContent":["import type multer from \"multer\";\nimport Express, {RouterOptions} from \"express\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {promisify} from \"util\";\nimport {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport {PlatformExpressHandler} from \"../services/PlatformExpressHandler\";\nimport {PlatformExpressResponse} from \"../services/PlatformExpressResponse\";\nimport {PlatformExpressRequest} from \"../services/PlatformExpressRequest\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\n\ndeclare module \"express\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Router extends Express.Router {}\n\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n\n export interface Request extends Express.Request {\n id: string;\n $ctx: PlatformContext;\n }\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {\n readonly providers = [\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 #multer: typeof multer;\n\n constructor(protected injector: InjectorService) {\n import(\"multer\").then(({default: multer}) => (this.#multer = multer));\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 PlatformBuilder.create<Express.Application, Express.Router>(module, {\n ...settings,\n adapter: PlatformExpress\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> = {}) {\n return PlatformBuilder.bootstrap<Express.Application, Express.Router>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n onInit() {\n this.injector.settings.middlewares = (this.injector.settings.middlewares || []).filter((middleware) => {\n const name = nameOf(middleware);\n if ([\"textParser\", \"jsonParser\", \"rawParser\", \"urlencodedParser\"].includes(name)) {\n this.injector.settings.set(`express.bodyParser.${name.replace(\"Parser\", \"\")}`, () => middleware);\n return false;\n }\n\n return true;\n });\n }\n\n useRouter(): this {\n const {logger} = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n logger.debug(\"Mount app router\");\n app.getApp().use(app.getRouter());\n\n return this;\n }\n\n async beforeLoadRoutes() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n // disable x-powered-by header\n injector.settings.get(\"env\") === Env.PROD && app.getApp().disable(\"x-powered-by\");\n\n await this.configureViewsEngine();\n }\n\n async afterLoadRoutes() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n // NOT FOUND\n app.use((req: any, res: any, next: any) => {\n !res.headersSent && injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound(req.$ctx);\n });\n\n // EXCEPTION FILTERS\n app.use((err: any, req: any, res: any, next: any) => {\n !res.headersSent && injector.get<PlatformExceptions>(PlatformExceptions)?.catch(err, req.$ctx);\n });\n }\n\n useContext(): this {\n const {logger} = this.injector;\n\n logger.debug(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n 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 multipart(options: PlatformMulterSettings): PlatformMulter {\n const m = this.#multer(options);\n\n const makePromise = (multer: any, name: string) => {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n }\n\n app() {\n const app = this.injector.settings.get(\"express.app\") || Express();\n return {\n app,\n callback() {\n return app;\n }\n };\n }\n\n router(routerOptions: Partial<RouterOptions> = {}) {\n const options = Object.assign(\n {\n mergeParams: true\n },\n this.injector.settings.express?.router || {},\n routerOptions\n );\n\n const router = Express.Router(options);\n\n return {\n router,\n callback() {\n return router;\n }\n };\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n return staticsMiddleware(root, props);\n }\n\n bodyParser(type: \"json\" | \"raw\" | \"text\" | \"urlencoded\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`express.bodyParser.${type}`);\n let parser: any = Express[type];\n let options: OptionsJson & OptionsText & OptionsUrlencoded = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n switch (type) {\n case \"urlencoded\":\n options.extended = true;\n break;\n case \"raw\":\n options.type = () => true;\n break;\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private async configureViewsEngine() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n try {\n const {exists, disabled} = this.injector.settings.get(\"views\") || {};\n\n if (exists && !disabled) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = injector.get<PlatformViews>(PlatformViews)!;\n const express = app.getApp();\n\n platformViews.getEngines().forEach(({extension, engine}) => {\n express.engine(extension, engine.render);\n });\n\n platformViews.viewEngine && express.set(\"view engine\", platformViews.viewEngine);\n platformViews.root && express.set(\"views\", platformViews.root);\n }\n } catch (error) {\n // istanbul ignore next\n 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"]}
@@ -25,7 +25,7 @@ const routerSettings_1 = require("./routerSettings");
25
25
  * @express
26
26
  */
27
27
  function CaseSensitive(caseSensitive) {
28
- return routerSettings_1.RouterSettings({ caseSensitive });
28
+ return (0, routerSettings_1.RouterSettings)({ caseSensitive });
29
29
  }
30
30
  exports.CaseSensitive = CaseSensitive;
31
31
  //# sourceMappingURL=caseSensitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caseSensitive.js","sourceRoot":"","sources":["../../../src/decorators/caseSensitive.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,aAAa,CAAC,aAAsB;IAClD,OAAO,IAAA,+BAAc,EAAC,EAAC,aAAa,EAAC,CAAC,CAAC;AACzC,CAAC;AAFD,sCAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @CaseSensitive(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param caseSensitive\n * @returns {Function}\n * @decorator\n * @express\n */\nexport function CaseSensitive(caseSensitive: boolean) {\n return RouterSettings({caseSensitive});\n}\n"]}
@@ -25,7 +25,7 @@ const routerSettings_1 = require("./routerSettings");
25
25
  * @express
26
26
  */
27
27
  function MergeParams(mergeParams = true) {
28
- return routerSettings_1.RouterSettings({ mergeParams });
28
+ return (0, routerSettings_1.RouterSettings)({ mergeParams });
29
29
  }
30
30
  exports.MergeParams = MergeParams;
31
31
  //# sourceMappingURL=mergeParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeParams.js","sourceRoot":"","sources":["../../../src/decorators/mergeParams.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,WAAW,CAAC,cAAuB,IAAI;IACrD,OAAO,IAAA,+BAAc,EAAC,EAAC,WAAW,EAAC,CAAC,CAAC;AACvC,CAAC;AAFD,kCAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @MergeParams(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param mergeParams\n * @returns {Function}\n * @decorator\n * @express\n */\nexport function MergeParams(mergeParams: boolean = true) {\n return RouterSettings({mergeParams});\n}\n"]}
@@ -26,7 +26,7 @@ const core_1 = require("@tsed/core");
26
26
  * @express
27
27
  */
28
28
  function RouterSettings(routerOptions) {
29
- return core_1.StoreMerge(common_1.ROUTER_OPTIONS, routerOptions);
29
+ return (0, core_1.StoreMerge)(common_1.ROUTER_OPTIONS, routerOptions);
30
30
  }
31
31
  exports.RouterSettings = RouterSettings;
32
32
  //# sourceMappingURL=routerSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routerSettings.js","sourceRoot":"","sources":["../../../src/decorators/routerSettings.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,qCAAsC;AAGtC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,cAAc,CAAC,aAA4B;IACzD,OAAO,IAAA,iBAAU,EAAC,uBAAc,EAAE,aAAa,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import {ROUTER_OPTIONS} from \"@tsed/common\";\nimport {StoreMerge} from \"@tsed/core\";\nimport {RouterOptions} from \"express\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @RouterSettings({mergeParams: true})\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * caseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * mergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {(target:any)=>void}\n * @decorator\n * @param routerOptions\n * @express\n */\nexport function RouterSettings(routerOptions: RouterOptions): Function {\n return StoreMerge(ROUTER_OPTIONS, routerOptions);\n}\n"]}
@@ -25,7 +25,7 @@ const routerSettings_1 = require("./routerSettings");
25
25
  * @express
26
26
  */
27
27
  function Strict(strict) {
28
- return routerSettings_1.RouterSettings({ strict });
28
+ return (0, routerSettings_1.RouterSettings)({ strict });
29
29
  }
30
30
  exports.Strict = Strict;
31
31
  //# sourceMappingURL=strict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strict.js","sourceRoot":"","sources":["../../../src/decorators/strict.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,MAAM,CAAC,MAAe;IACpC,OAAO,IAAA,+BAAc,EAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @Strict(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param strict\n * @returns {Function}\n * @decorator\n * @express\n */\nexport function Strict(strict: boolean) {\n return RouterSettings({strict});\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const common_1 = require("@tsed/common");
4
+ const PlatformExpress_1 = require("./components/PlatformExpress");
5
+ common_1.PlatformTest.adapter = PlatformExpress_1.PlatformExpress;
6
+ common_1.PlatformBuilder.adapter = PlatformExpress_1.PlatformExpress;
7
+ //# sourceMappingURL=exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";;AAAA,yCAA2D;AAC3D,kEAA6D;AAE7D,qBAAY,CAAC,OAAO,GAAG,iCAAsB,CAAC;AAC9C,wBAAe,CAAC,OAAO,GAAG,iCAAsB,CAAC","sourcesContent":["import {PlatformBuilder, PlatformTest} from \"@tsed/common\";\nimport {PlatformExpress} from \"./components/PlatformExpress\";\n\nPlatformTest.adapter = PlatformExpress as any;\nPlatformBuilder.adapter = PlatformExpress as any;\n"]}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const tslib_1 = require("tslib");
7
+ tslib_1.__exportStar(require("./exports"), exports);
8
+ tslib_1.__exportStar(require("./components/PlatformExpress"), exports);
9
+ tslib_1.__exportStar(require("./decorators/caseSensitive"), exports);
10
+ tslib_1.__exportStar(require("./decorators/mergeParams"), exports);
11
+ tslib_1.__exportStar(require("./decorators/routerSettings"), exports);
12
+ tslib_1.__exportStar(require("./decorators/strict"), exports);
13
+ tslib_1.__exportStar(require("./interfaces/PlatformExpressSettings"), exports);
14
+ tslib_1.__exportStar(require("./interfaces/PlatformExpressStaticsOptions"), exports);
15
+ tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
16
+ tslib_1.__exportStar(require("./middlewares/staticsMiddleware"), exports);
17
+ tslib_1.__exportStar(require("./services/PlatformExpressHandler"), exports);
18
+ tslib_1.__exportStar(require("./services/PlatformExpressRequest"), exports);
19
+ tslib_1.__exportStar(require("./services/PlatformExpressResponse"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,uEAA6C;AAC7C,qEAA2C;AAC3C,mEAAyC;AACzC,sEAA4C;AAC5C,8DAAoC;AACpC,+EAAqD;AACrD,qFAA2D;AAC3D,kEAAwC;AACxC,0EAAgD;AAChD,4EAAkD;AAClD,4EAAkD;AAClD,6EAAmD","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformExpress\";\nexport * from \"./decorators/caseSensitive\";\nexport * from \"./decorators/mergeParams\";\nexport * from \"./decorators/routerSettings\";\nexport * from \"./decorators/strict\";\nexport * from \"./interfaces/PlatformExpressSettings\";\nexport * from \"./interfaces/PlatformExpressStaticsOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformExpressHandler\";\nexport * from \"./services/PlatformExpressRequest\";\nexport * from \"./services/PlatformExpressResponse\";\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {RouterOptions} from \"express\";\nimport type {OptionsJson, OptionsText, Options, OptionsUrlencoded} from \"body-parser\";\nimport type {NextHandleFunction} from \"connect\";\n\nexport interface PlatformExpressSettings {\n /**\n * Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).\n */\n router?: RouterOptions;\n /**\n * Express application\n */\n app?: Express.Application;\n\n /**\n * body parser configuration\n */\n bodyParser?: {\n json?: (opts?: OptionsJson) => NextHandleFunction | OptionsJson;\n text?: (opts?: OptionsText) => NextHandleFunction | OptionsText;\n raw?: (opts?: Options) => NextHandleFunction | Options;\n urlencoded?: (opts?: OptionsUrlencoded) => NextHandleFunction | OptionsUrlencoded;\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressStaticsOptions.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressStaticsOptions.ts"],"names":[],"mappings":"","sourcesContent":["import Express from \"express\";\n\nexport interface PlatformExpressStaticsOptions {\n /**\n * Enable or disable setting Cache-Control response header, defaults to true.\n * Disabling this will ignore the immutable and maxAge options.\n */\n cacheControl?: boolean;\n\n /**\n * Set how \"dotfiles\" are treated when encountered. A dotfile is a file or directory that begins with a dot (\".\").\n * Note this check is done on the path itself without checking if the path actually exists on the disk.\n * If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to \"deny\").\n * The default value is 'ignore'.\n * 'allow' No special treatment for dotfiles\n * 'deny' Send a 403 for any request for a dotfile\n * 'ignore' Pretend like the dotfile does not exist and call next()\n */\n dotfiles?: string;\n\n /**\n * Enable or disable etag generation, defaults to true.\n */\n etag?: boolean;\n\n /**\n * Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for.\n * The first that exists will be served. Example: ['html', 'htm'].\n * The default value is false.\n */\n extensions?: string[] | false;\n\n /**\n * Let client errors fall-through as unhandled requests, otherwise forward a client error.\n * The default value is true.\n */\n fallthrough?: boolean;\n\n /**\n * Enable or disable the immutable directive in the Cache-Control response header.\n * If enabled, the maxAge option should also be specified to enable caching. The immutable directive will prevent supported clients from making conditional requests during the life of the maxAge option to check if the file has changed.\n */\n immutable?: boolean;\n\n /**\n * By default this module will send \"index.html\" files in response to a request on a directory.\n * To disable this set false or to supply a new index pass a string or an array in preferred order.\n */\n index?: boolean | string | string[];\n\n /**\n * Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.\n */\n lastModified?: boolean;\n\n /**\n * Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.\n */\n maxAge?: number | string;\n\n /**\n * Redirect to trailing \"/\" when the pathname is a dir. Defaults to true.\n */\n redirect?: boolean;\n\n /**\n * Function to set custom headers on response. Alterations to the headers need to occur synchronously.\n * The function is called as fn(res, path, stat), where the arguments are:\n * res the response object\n * path the file path that is being sent\n * stat the stat object of the file that is being sent\n */\n setHeaders?: (res: Express.Response, path: string, stat: any) => any;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import Express from \"express\";\nimport {PlatformExpressSettings} from \"./PlatformExpressSettings\";\n\ndeclare global {\n namespace TsED {\n export interface Configuration {\n /**\n * Configuration related to Express platform application.\n */\n express: PlatformExpressSettings;\n }\n\n export interface NextFunction extends Express.NextFunction {}\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staticsMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/staticsMiddleware.ts"],"names":[],"mappings":";;;;AAAA,8DAA8B;AAE9B;;GAEG;AACH,SAAgB,iBAAiB,CAAC,SAAiB,EAAE,UAAe,EAAE;IACpE,MAAM,UAAU,GAAG,iBAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAEtD,OAAO,CAAC,OAAY,EAAE,QAAa,EAAE,IAAS,EAAE,EAAE;QAChD,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE;YACzB,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;SACrC;aAAM;YACL,IAAI,EAAE,CAAC;SACR;IACH,CAAC,CAAC;AACJ,CAAC;AAVD,8CAUC","sourcesContent":["import Express from \"express\";\n\n/**\n * @ignore\n */\nexport function staticsMiddleware(directory: string, options: any = {}) {\n const middleware = Express.static(directory, options);\n\n return (request: any, response: any, next: any) => {\n if (!response.headersSent) {\n middleware(request, response, next);\n } else {\n next();\n }\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressHandler.ts"],"names":[],"mappings":";;;AAAA,yCAA6F;AAE7F;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,wBAAe;IAC/C,gBAAgB,CAAC,QAAyB;QAClD,IAAI,QAAQ,CAAC,IAAI,KAAK,oBAAW,CAAC,cAAc,EAAE;YAChD,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC9C,OAAO,KAAK,EAAE,GAAQ,EAAE,GAAQ,EAAE,GAAQ,EAAE,IAAS,EAAE,EAAE,CACvD,OAAO,CAAC;gBACN,GAAG;gBACH,IAAI;gBACJ,IAAI,EAAE,GAAG,CAAC,IAAI;aACf,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,cAAgC;QAC3D,IAAI;YACF,OAAO,MAAM,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;SACjD;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;SACzC;IACH,CAAC;CACF;AAtBD,wDAsBC","sourcesContent":["import {HandlerMetadata, HandlerType, OnRequestOptions, PlatformHandler} from \"@tsed/common\";\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressHandler extends PlatformHandler {\n protected createRawHandler(metadata: HandlerMetadata): Function {\n if (metadata.type === HandlerType.ERR_MIDDLEWARE) {\n const handler = this.compileHandler(metadata);\n return async (err: any, req: any, res: any, next: any) =>\n handler({\n err,\n next,\n $ctx: req.$ctx\n });\n }\n\n return super.createRawHandler(metadata);\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n try {\n return await super.onCtxRequest(requestOptions);\n } catch (er) {\n return this.onError(er, requestOptions);\n }\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressRequest.ts"],"names":[],"mappings":";;;AAAA,yCAA8D;AAG9D;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,wBAAgC;CAAG;AAA/E,wDAA+E","sourcesContent":["import {PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport type Express from \"express\";\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressRequest extends PlatformRequest<Express.Request> {}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressResponse.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;AAS9C;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,yBAAkC;CAAG;AAAlF,0DAAkF","sourcesContent":["import {PlatformResponse} from \"@tsed/common\";\nimport type Express from \"express\";\n\ndeclare global {\n namespace TsED {\n export interface Response extends Express.Response {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressResponse extends PlatformResponse<Express.Response> {}\n"]}
@@ -0,0 +1,196 @@
1
+ var _PlatformExpress_multer;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import Express from "express";
4
+ import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
5
+ import { promisify } from "util";
6
+ import { Env, isFunction, nameOf } from "@tsed/core";
7
+ import { PlatformExpressHandler } from "../services/PlatformExpressHandler.js";
8
+ import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
9
+ import { PlatformExpressRequest } from "../services/PlatformExpressRequest.js";
10
+ import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
11
+ /**
12
+ * @platform
13
+ * @express
14
+ */
15
+ export class PlatformExpress {
16
+ constructor(injector) {
17
+ this.injector = injector;
18
+ this.providers = [
19
+ {
20
+ provide: PlatformHandler,
21
+ useClass: PlatformExpressHandler
22
+ },
23
+ {
24
+ provide: PlatformResponse,
25
+ useClass: PlatformExpressResponse
26
+ },
27
+ {
28
+ provide: PlatformRequest,
29
+ useClass: PlatformExpressRequest
30
+ }
31
+ ];
32
+ _PlatformExpress_multer.set(this, void 0);
33
+ import("multer").then(({ default: multer }) => (__classPrivateFieldSet(this, _PlatformExpress_multer, multer, "f")));
34
+ }
35
+ /**
36
+ * Create new serverless application. In this mode, the component scan are disabled.
37
+ * @param module
38
+ * @param settings
39
+ */
40
+ static create(module, settings = {}) {
41
+ return PlatformBuilder.create(module, {
42
+ ...settings,
43
+ adapter: PlatformExpress
44
+ });
45
+ }
46
+ /**
47
+ * Bootstrap a server application
48
+ * @param module
49
+ * @param settings
50
+ */
51
+ static async bootstrap(module, settings = {}) {
52
+ return PlatformBuilder.bootstrap(module, {
53
+ ...settings,
54
+ adapter: PlatformExpress
55
+ });
56
+ }
57
+ onInit() {
58
+ this.injector.settings.middlewares = (this.injector.settings.middlewares || []).filter((middleware) => {
59
+ const name = nameOf(middleware);
60
+ if (["textParser", "jsonParser", "rawParser", "urlencodedParser"].includes(name)) {
61
+ this.injector.settings.set(`express.bodyParser.${name.replace("Parser", "")}`, () => middleware);
62
+ return false;
63
+ }
64
+ return true;
65
+ });
66
+ }
67
+ useRouter() {
68
+ const { logger } = this.injector;
69
+ const app = this.injector.get(PlatformApplication);
70
+ logger.debug("Mount app router");
71
+ app.getApp().use(app.getRouter());
72
+ return this;
73
+ }
74
+ async beforeLoadRoutes() {
75
+ const injector = this.injector;
76
+ const app = this.injector.get(PlatformApplication);
77
+ // disable x-powered-by header
78
+ injector.settings.get("env") === Env.PROD && app.getApp().disable("x-powered-by");
79
+ await this.configureViewsEngine();
80
+ }
81
+ async afterLoadRoutes() {
82
+ const injector = this.injector;
83
+ const app = this.injector.get(PlatformApplication);
84
+ // NOT FOUND
85
+ app.use((req, res, next) => {
86
+ var _a;
87
+ !res.headersSent && ((_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.resourceNotFound(req.$ctx));
88
+ });
89
+ // EXCEPTION FILTERS
90
+ app.use((err, req, res, next) => {
91
+ var _a;
92
+ !res.headersSent && ((_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(err, req.$ctx));
93
+ });
94
+ }
95
+ useContext() {
96
+ const { logger } = this.injector;
97
+ logger.debug("Mount app context");
98
+ const invoke = createContext(this.injector);
99
+ const app = this.injector.get(PlatformApplication);
100
+ app.getApp().use(async (request, response, next) => {
101
+ await invoke({ request, response });
102
+ return next();
103
+ });
104
+ return this;
105
+ }
106
+ multipart(options) {
107
+ const m = __classPrivateFieldGet(this, _PlatformExpress_multer, "f").call(this, options);
108
+ const makePromise = (multer, name) => {
109
+ // istanbul ignore next
110
+ if (!multer[name])
111
+ return;
112
+ const fn = multer[name];
113
+ multer[name] = function apply(...args) {
114
+ const middleware = Reflect.apply(fn, this, args);
115
+ return (req, res) => promisify(middleware)(req, res);
116
+ };
117
+ };
118
+ makePromise(m, "any");
119
+ makePromise(m, "array");
120
+ makePromise(m, "fields");
121
+ makePromise(m, "none");
122
+ makePromise(m, "single");
123
+ return m;
124
+ }
125
+ app() {
126
+ const app = this.injector.settings.get("express.app") || Express();
127
+ return {
128
+ app,
129
+ callback() {
130
+ return app;
131
+ }
132
+ };
133
+ }
134
+ router(routerOptions = {}) {
135
+ var _a;
136
+ const options = Object.assign({
137
+ mergeParams: true
138
+ }, ((_a = this.injector.settings.express) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
139
+ const router = Express.Router(options);
140
+ return {
141
+ router,
142
+ callback() {
143
+ return router;
144
+ }
145
+ };
146
+ }
147
+ statics(endpoint, options) {
148
+ const { root, ...props } = options;
149
+ return staticsMiddleware(root, props);
150
+ }
151
+ bodyParser(type, additionalOptions = {}) {
152
+ const opts = this.injector.settings.get(`express.bodyParser.${type}`);
153
+ let parser = Express[type];
154
+ let options = {};
155
+ if (isFunction(opts)) {
156
+ parser = opts;
157
+ options = {};
158
+ }
159
+ switch (type) {
160
+ case "urlencoded":
161
+ options.extended = true;
162
+ break;
163
+ case "raw":
164
+ options.type = () => true;
165
+ break;
166
+ }
167
+ return parser({ ...options, ...additionalOptions });
168
+ }
169
+ async configureViewsEngine() {
170
+ const injector = this.injector;
171
+ const app = this.injector.get(PlatformApplication);
172
+ try {
173
+ const { exists, disabled } = this.injector.settings.get("views") || {};
174
+ if (exists && !disabled) {
175
+ const { PlatformViews } = await import("@tsed/platform-views");
176
+ const platformViews = injector.get(PlatformViews);
177
+ const express = app.getApp();
178
+ platformViews.getEngines().forEach(({ extension, engine }) => {
179
+ express.engine(extension, engine.render);
180
+ });
181
+ platformViews.viewEngine && express.set("view engine", platformViews.viewEngine);
182
+ platformViews.root && express.set("views", platformViews.root);
183
+ }
184
+ }
185
+ catch (error) {
186
+ // istanbul ignore next
187
+ injector.logger.warn({
188
+ event: "PLATFORM_VIEWS_ERROR",
189
+ message: "Unable to configure the PlatformViews service on your environment.",
190
+ error
191
+ });
192
+ }
193
+ }
194
+ }
195
+ _PlatformExpress_multer = new WeakMap();
196
+ //# sourceMappingURL=PlatformExpress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;AACA,OAAO,OAAwB,MAAM,SAAS,CAAC;AAE/C,OAAO,EACL,aAAa,EAGb,mBAAmB,EACnB,eAAe,EAEf,kBAAkB,EAClB,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AACzD,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AA0BnE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAiB1B,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAhBtC,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,sBAAsB;aACjC;YACD;gBACE,OAAO,EAAE,gBAAgB;gBACzB,QAAQ,EAAE,uBAAuB;aAClC;YACD;gBACE,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,sBAAsB;aACjC;SACF,CAAC;QACF,0CAAuB;QAGrB,MAAM,CAAC,QAAQ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O,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;gBACjF,aAAa,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;aAChE;SACF;QAAC,OAAO,KAAK,EAAE;YACd,uBAAuB;YACvB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;CACF","sourcesContent":["import type multer from \"multer\";\nimport Express, {RouterOptions} from \"express\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {promisify} from \"util\";\nimport {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport {PlatformExpressHandler} from \"../services/PlatformExpressHandler\";\nimport {PlatformExpressResponse} from \"../services/PlatformExpressResponse\";\nimport {PlatformExpressRequest} from \"../services/PlatformExpressRequest\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\n\ndeclare module \"express\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Router extends Express.Router {}\n\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n\n export interface Request extends Express.Request {\n id: string;\n $ctx: PlatformContext;\n }\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {\n readonly providers = [\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 #multer: typeof multer;\n\n constructor(protected injector: InjectorService) {\n import(\"multer\").then(({default: multer}) => (this.#multer = multer));\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 PlatformBuilder.create<Express.Application, Express.Router>(module, {\n ...settings,\n adapter: PlatformExpress\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> = {}) {\n return PlatformBuilder.bootstrap<Express.Application, Express.Router>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n onInit() {\n this.injector.settings.middlewares = (this.injector.settings.middlewares || []).filter((middleware) => {\n const name = nameOf(middleware);\n if ([\"textParser\", \"jsonParser\", \"rawParser\", \"urlencodedParser\"].includes(name)) {\n this.injector.settings.set(`express.bodyParser.${name.replace(\"Parser\", \"\")}`, () => middleware);\n return false;\n }\n\n return true;\n });\n }\n\n useRouter(): this {\n const {logger} = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n logger.debug(\"Mount app router\");\n app.getApp().use(app.getRouter());\n\n return this;\n }\n\n async beforeLoadRoutes() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n // disable x-powered-by header\n injector.settings.get(\"env\") === Env.PROD && app.getApp().disable(\"x-powered-by\");\n\n await this.configureViewsEngine();\n }\n\n async afterLoadRoutes() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n // NOT FOUND\n app.use((req: any, res: any, next: any) => {\n !res.headersSent && injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound(req.$ctx);\n });\n\n // EXCEPTION FILTERS\n app.use((err: any, req: any, res: any, next: any) => {\n !res.headersSent && injector.get<PlatformExceptions>(PlatformExceptions)?.catch(err, req.$ctx);\n });\n }\n\n useContext(): this {\n const {logger} = this.injector;\n\n logger.debug(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n 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 multipart(options: PlatformMulterSettings): PlatformMulter {\n const m = this.#multer(options);\n\n const makePromise = (multer: any, name: string) => {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n }\n\n app() {\n const app = this.injector.settings.get(\"express.app\") || Express();\n return {\n app,\n callback() {\n return app;\n }\n };\n }\n\n router(routerOptions: Partial<RouterOptions> = {}) {\n const options = Object.assign(\n {\n mergeParams: true\n },\n this.injector.settings.express?.router || {},\n routerOptions\n );\n\n const router = Express.Router(options);\n\n return {\n router,\n callback() {\n return router;\n }\n };\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n return staticsMiddleware(root, props);\n }\n\n bodyParser(type: \"json\" | \"raw\" | \"text\" | \"urlencoded\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`express.bodyParser.${type}`);\n let parser: any = Express[type];\n let options: OptionsJson & OptionsText & OptionsUrlencoded = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n switch (type) {\n case \"urlencoded\":\n options.extended = true;\n break;\n case \"raw\":\n options.type = () => true;\n break;\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private async configureViewsEngine() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n try {\n const {exists, disabled} = this.injector.settings.get(\"views\") || {};\n\n if (exists && !disabled) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = injector.get<PlatformViews>(PlatformViews)!;\n const express = app.getApp();\n\n platformViews.getEngines().forEach(({extension, engine}) => {\n express.engine(extension, engine.render);\n });\n\n platformViews.viewEngine && express.set(\"view engine\", platformViews.viewEngine);\n platformViews.root && express.set(\"views\", platformViews.root);\n }\n } catch (error) {\n // istanbul ignore next\n 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"]}