@tsed/platform-express 6.110.2 → 6.113.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.
Files changed (32) hide show
  1. package/lib/cjs/components/PlatformExpress.js +96 -45
  2. package/lib/cjs/components/PlatformExpress.js.map +1 -1
  3. package/lib/cjs/index.js +0 -3
  4. package/lib/cjs/index.js.map +1 -1
  5. package/lib/cjs/interfaces/PlatformExpressSettings.js.map +1 -1
  6. package/lib/cjs/services/PlatformExpressRequest.js.map +1 -1
  7. package/lib/esm/components/PlatformExpress.js +97 -23
  8. package/lib/esm/components/PlatformExpress.js.map +1 -1
  9. package/lib/esm/index.js +0 -3
  10. package/lib/esm/index.js.map +1 -1
  11. package/lib/esm/interfaces/PlatformExpressSettings.js.map +1 -1
  12. package/lib/esm/services/PlatformExpressRequest.js.map +1 -1
  13. package/lib/types/components/PlatformExpress.d.ts +38 -8
  14. package/lib/types/index.d.ts +0 -3
  15. package/lib/types/interfaces/PlatformExpressSettings.d.ts +15 -1
  16. package/lib/types/services/PlatformExpressRequest.d.ts +1 -15
  17. package/package.json +13 -13
  18. package/lib/cjs/middlewares/rawBodyMiddleware.js +0 -27
  19. package/lib/cjs/middlewares/rawBodyMiddleware.js.map +0 -1
  20. package/lib/cjs/services/PlatformExpressApplication.js +0 -32
  21. package/lib/cjs/services/PlatformExpressApplication.js.map +0 -1
  22. package/lib/cjs/services/PlatformExpressRouter.js +0 -34
  23. package/lib/cjs/services/PlatformExpressRouter.js.map +0 -1
  24. package/lib/esm/middlewares/rawBodyMiddleware.js +0 -22
  25. package/lib/esm/middlewares/rawBodyMiddleware.js.map +0 -1
  26. package/lib/esm/services/PlatformExpressApplication.js +0 -29
  27. package/lib/esm/services/PlatformExpressApplication.js.map +0 -1
  28. package/lib/esm/services/PlatformExpressRouter.js +0 -31
  29. package/lib/esm/services/PlatformExpressRouter.js.map +0 -1
  30. package/lib/types/middlewares/rawBodyMiddleware.d.ts +0 -4
  31. package/lib/types/services/PlatformExpressApplication.d.ts +0 -24
  32. package/lib/types/services/PlatformExpressRouter.d.ts +0 -18
@@ -1,53 +1,24 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
2
+ var _PlatformExpress_multer;
25
3
  Object.defineProperty(exports, "__esModule", { value: true });
26
4
  exports.PlatformExpress = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const express_1 = tslib_1.__importDefault(require("express"));
27
7
  const common_1 = require("@tsed/common");
8
+ const util_1 = require("util");
28
9
  const core_1 = require("@tsed/core");
29
- const rawBodyMiddleware_1 = require("../middlewares/rawBodyMiddleware");
30
- const PlatformExpressApplication_1 = require("../services/PlatformExpressApplication");
31
- const PlatformExpressRouter_1 = require("../services/PlatformExpressRouter");
32
10
  const PlatformExpressHandler_1 = require("../services/PlatformExpressHandler");
33
11
  const PlatformExpressResponse_1 = require("../services/PlatformExpressResponse");
34
12
  const PlatformExpressRequest_1 = require("../services/PlatformExpressRequest");
13
+ const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
35
14
  /**
36
15
  * @platform
37
16
  * @express
38
17
  */
39
18
  class PlatformExpress {
40
- constructor(platform) {
41
- this.platform = platform;
19
+ constructor(injector) {
20
+ this.injector = injector;
42
21
  this.providers = [
43
- {
44
- provide: common_1.PlatformApplication,
45
- useClass: PlatformExpressApplication_1.PlatformExpressApplication
46
- },
47
- {
48
- provide: common_1.PlatformRouter,
49
- useClass: PlatformExpressRouter_1.PlatformExpressRouter
50
- },
51
22
  {
52
23
  provide: common_1.PlatformHandler,
53
24
  useClass: PlatformExpressHandler_1.PlatformExpressHandler
@@ -61,6 +32,8 @@ class PlatformExpress {
61
32
  useClass: PlatformExpressRequest_1.PlatformExpressRequest
62
33
  }
63
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")));
64
37
  }
65
38
  /**
66
39
  * Create new serverless application. In this mode, the component scan are disabled.
@@ -84,21 +57,33 @@ class PlatformExpress {
84
57
  adapter: PlatformExpress
85
58
  });
86
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
+ }
87
70
  useRouter() {
88
- const { logger, app } = this.platform;
71
+ const { logger } = this.injector;
72
+ const app = this.injector.get(common_1.PlatformApplication);
89
73
  logger.debug("Mount app router");
90
- app.getApp().use(rawBodyMiddleware_1.rawBodyMiddleware);
91
74
  app.getApp().use(app.getRouter());
92
75
  return this;
93
76
  }
94
77
  async beforeLoadRoutes() {
95
- const { injector, app } = this.platform;
78
+ const injector = this.injector;
79
+ const app = this.injector.get(common_1.PlatformApplication);
96
80
  // disable x-powered-by header
97
81
  injector.settings.get("env") === core_1.Env.PROD && app.getApp().disable("x-powered-by");
98
82
  await this.configureViewsEngine();
99
83
  }
100
84
  async afterLoadRoutes() {
101
- const { injector, app } = this.platform;
85
+ const injector = this.injector;
86
+ const app = this.injector.get(common_1.PlatformApplication);
102
87
  // NOT FOUND
103
88
  app.use((req, res, next) => {
104
89
  var _a;
@@ -111,21 +96,86 @@ class PlatformExpress {
111
96
  });
112
97
  }
113
98
  useContext() {
114
- const { logger, app, injector } = this.platform;
99
+ const { logger } = this.injector;
115
100
  logger.debug("Mount app context");
116
- const invoke = (0, common_1.createContext)(injector);
101
+ const invoke = (0, common_1.createContext)(this.injector);
102
+ const app = this.injector.get(common_1.PlatformApplication);
117
103
  app.getApp().use(async (request, response, next) => {
118
104
  await invoke({ request, response });
119
105
  return next();
120
106
  });
121
107
  return this;
122
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
+ }
123
172
  async configureViewsEngine() {
124
- const { settings, injector, app } = this.platform;
173
+ const injector = this.injector;
174
+ const app = this.injector.get(common_1.PlatformApplication);
125
175
  try {
126
- const { exists, disabled } = settings.get("views") || {};
176
+ const { exists, disabled } = this.injector.settings.get("views") || {};
127
177
  if (exists && !disabled) {
128
- const { PlatformViews } = await Promise.resolve().then(() => __importStar(require("@tsed/platform-views")));
178
+ const { PlatformViews } = await Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/platform-views")));
129
179
  const platformViews = injector.get(PlatformViews);
130
180
  const express = app.getApp();
131
181
  platformViews.getEngines().forEach(({ extension, engine }) => {
@@ -146,4 +196,5 @@ class PlatformExpress {
146
196
  }
147
197
  }
148
198
  exports.PlatformExpress = PlatformExpress;
199
+ _PlatformExpress_multer = new WeakMap();
149
200
  //# sourceMappingURL=PlatformExpress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAUsB;AACtB,qCAAqC;AACrC,wEAAmE;AACnE,uFAAkF;AAClF,6EAAwE;AACxE,+EAA0E;AAC1E,iFAA4E;AAC5E,+EAA0E;AAE1E;;;GAGG;AACH,MAAa,eAAe;IAwB1B,YAAoB,QAA8D;QAA9D,aAAQ,GAAR,QAAQ,CAA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PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter\n} from \"@tsed/common\";\nimport {Env, Type} from \"@tsed/core\";\nimport {rawBodyMiddleware} from \"../middlewares/rawBodyMiddleware\";\nimport {PlatformExpressApplication} from \"../services/PlatformExpressApplication\";\nimport {PlatformExpressRouter} from \"../services/PlatformExpressRouter\";\nimport {PlatformExpressHandler} from \"../services/PlatformExpressHandler\";\nimport {PlatformExpressResponse} from \"../services/PlatformExpressResponse\";\nimport {PlatformExpressRequest} from \"../services/PlatformExpressRequest\";\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {\n readonly 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 constructor(private platform: PlatformBuilder<Express.Application, Express.Router>) {}\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 useRouter(): this {\n const {logger, app} = this.platform;\n\n logger.debug(\"Mount app router\");\n app.getApp().use(rawBodyMiddleware);\n app.getApp().use(app.getRouter());\n\n return this;\n }\n\n async beforeLoadRoutes() {\n const {injector, app} = this.platform;\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, app} = this.platform;\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, app, injector} = this.platform;\n\n logger.debug(\"Mount app context\");\n\n const invoke = createContext(injector);\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 private async configureViewsEngine() {\n const {settings, injector, app} = this.platform;\n try {\n const {exists, disabled} = 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"]}
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;gB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C;gBAE7B,aAAa,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,EAAE;oBACzD,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,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"]}
package/lib/cjs/index.js CHANGED
@@ -13,11 +13,8 @@ tslib_1.__exportStar(require("./decorators/strict"), exports);
13
13
  tslib_1.__exportStar(require("./interfaces/PlatformExpressSettings"), exports);
14
14
  tslib_1.__exportStar(require("./interfaces/PlatformExpressStaticsOptions"), exports);
15
15
  tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
16
- tslib_1.__exportStar(require("./middlewares/rawBodyMiddleware"), exports);
17
16
  tslib_1.__exportStar(require("./middlewares/staticsMiddleware"), exports);
18
- tslib_1.__exportStar(require("./services/PlatformExpressApplication"), exports);
19
17
  tslib_1.__exportStar(require("./services/PlatformExpressHandler"), exports);
20
18
  tslib_1.__exportStar(require("./services/PlatformExpressRequest"), exports);
21
19
  tslib_1.__exportStar(require("./services/PlatformExpressResponse"), exports);
22
- tslib_1.__exportStar(require("./services/PlatformExpressRouter"), exports);
23
20
  //# sourceMappingURL=index.js.map
@@ -1 +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,0EAAgD;AAChD,gFAAsD;AACtD,4EAAkD;AAClD,4EAAkD;AAClD,6EAAmD;AACnD,2EAAiD","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/rawBodyMiddleware\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformExpressApplication\";\nexport * from \"./services/PlatformExpressHandler\";\nexport * from \"./services/PlatformExpressRequest\";\nexport * from \"./services/PlatformExpressResponse\";\nexport * from \"./services/PlatformExpressRouter\";\n"]}
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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {RouterOptions} from \"express\";\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 app?: Express.Application;\n}\n"]}
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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpressRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressRequest.ts"],"names":[],"mappings":";;;AAAA,yCAA8D;AAmB9D;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,wBAAgC;CAAG;AAA/E,wDAA+E","sourcesContent":["import {PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport type Express from \"express\";\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 Request extends Express.Request {\n id: string;\n $ctx: PlatformContext;\n }\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressRequest extends PlatformRequest<Express.Request> {}\n"]}
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"]}
@@ -1,27 +1,21 @@
1
- import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
2
- import { Env } from "@tsed/core";
3
- import { rawBodyMiddleware } from "../middlewares/rawBodyMiddleware.js";
4
- import { PlatformExpressApplication } from "../services/PlatformExpressApplication.js";
5
- import { PlatformExpressRouter } from "../services/PlatformExpressRouter.js";
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";
6
7
  import { PlatformExpressHandler } from "../services/PlatformExpressHandler.js";
7
8
  import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
8
9
  import { PlatformExpressRequest } from "../services/PlatformExpressRequest.js";
10
+ import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
9
11
  /**
10
12
  * @platform
11
13
  * @express
12
14
  */
13
15
  export class PlatformExpress {
14
- constructor(platform) {
15
- this.platform = platform;
16
+ constructor(injector) {
17
+ this.injector = injector;
16
18
  this.providers = [
17
- {
18
- provide: PlatformApplication,
19
- useClass: PlatformExpressApplication
20
- },
21
- {
22
- provide: PlatformRouter,
23
- useClass: PlatformExpressRouter
24
- },
25
19
  {
26
20
  provide: PlatformHandler,
27
21
  useClass: PlatformExpressHandler
@@ -35,6 +29,8 @@ export class PlatformExpress {
35
29
  useClass: PlatformExpressRequest
36
30
  }
37
31
  ];
32
+ _PlatformExpress_multer.set(this, void 0);
33
+ import("multer").then(({ default: multer }) => (__classPrivateFieldSet(this, _PlatformExpress_multer, multer, "f")));
38
34
  }
39
35
  /**
40
36
  * Create new serverless application. In this mode, the component scan are disabled.
@@ -58,21 +54,33 @@ export class PlatformExpress {
58
54
  adapter: PlatformExpress
59
55
  });
60
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
+ }
61
67
  useRouter() {
62
- const { logger, app } = this.platform;
68
+ const { logger } = this.injector;
69
+ const app = this.injector.get(PlatformApplication);
63
70
  logger.debug("Mount app router");
64
- app.getApp().use(rawBodyMiddleware);
65
71
  app.getApp().use(app.getRouter());
66
72
  return this;
67
73
  }
68
74
  async beforeLoadRoutes() {
69
- const { injector, app } = this.platform;
75
+ const injector = this.injector;
76
+ const app = this.injector.get(PlatformApplication);
70
77
  // disable x-powered-by header
71
78
  injector.settings.get("env") === Env.PROD && app.getApp().disable("x-powered-by");
72
79
  await this.configureViewsEngine();
73
80
  }
74
81
  async afterLoadRoutes() {
75
- const { injector, app } = this.platform;
82
+ const injector = this.injector;
83
+ const app = this.injector.get(PlatformApplication);
76
84
  // NOT FOUND
77
85
  app.use((req, res, next) => {
78
86
  var _a;
@@ -85,19 +93,84 @@ export class PlatformExpress {
85
93
  });
86
94
  }
87
95
  useContext() {
88
- const { logger, app, injector } = this.platform;
96
+ const { logger } = this.injector;
89
97
  logger.debug("Mount app context");
90
- const invoke = createContext(injector);
98
+ const invoke = createContext(this.injector);
99
+ const app = this.injector.get(PlatformApplication);
91
100
  app.getApp().use(async (request, response, next) => {
92
101
  await invoke({ request, response });
93
102
  return next();
94
103
  });
95
104
  return this;
96
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
+ }
97
169
  async configureViewsEngine() {
98
- const { settings, injector, app } = this.platform;
170
+ const injector = this.injector;
171
+ const app = this.injector.get(PlatformApplication);
99
172
  try {
100
- const { exists, disabled } = settings.get("views") || {};
173
+ const { exists, disabled } = this.injector.settings.get("views") || {};
101
174
  if (exists && !disabled) {
102
175
  const { PlatformViews } = await import("@tsed/platform-views");
103
176
  const platformViews = injector.get(PlatformViews);
@@ -119,4 +192,5 @@ export class PlatformExpress {
119
192
  }
120
193
  }
121
194
  }
195
+ _PlatformExpress_multer = new WeakMap();
122
196
  //# sourceMappingURL=PlatformExpress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EAEb,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,GAAG,EAAO,MAAM,YAAY,CAAC;AACrC,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAC,0BAA0B,EAAC,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAC,qBAAqB,EAAC,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAE1E;;;GAGG;AACH,MAAM,OAAO,eAAe;IAwB1B,YAAoB,QAA8D;QAA9D,aAAQ,GAAR,QAAQ,CAAsD;QAvBzE,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C,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,KAAK,CAAC,oBAAoB;QAChC,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QAChD,IAAI;YACF,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAEvD,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;gBACvB,MAAM,EAAC,aAAa,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;gBAC7D,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAgB,aAAa,CAAE,CAAC;gBAClE,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;gBAE7B,aAAa,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,EAAE;oBACzD,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,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","sourcesContent":["import Express from \"express\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {\n createContext,\n PlatformAdapter,\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 {rawBodyMiddleware} from \"../middlewares/rawBodyMiddleware\";\nimport {PlatformExpressApplication} from \"../services/PlatformExpressApplication\";\nimport {PlatformExpressRouter} from \"../services/PlatformExpressRouter\";\nimport {PlatformExpressHandler} from \"../services/PlatformExpressHandler\";\nimport {PlatformExpressResponse} from \"../services/PlatformExpressResponse\";\nimport {PlatformExpressRequest} from \"../services/PlatformExpressRequest\";\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {\n readonly 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 constructor(private platform: PlatformBuilder<Express.Application, Express.Router>) {}\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 useRouter(): this {\n const {logger, app} = this.platform;\n\n logger.debug(\"Mount app router\");\n app.getApp().use(rawBodyMiddleware);\n app.getApp().use(app.getRouter());\n\n return this;\n }\n\n async beforeLoadRoutes() {\n const {injector, app} = this.platform;\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, app} = this.platform;\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, app, injector} = this.platform;\n\n logger.debug(\"Mount app context\");\n\n const invoke = createContext(injector);\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 private async configureViewsEngine() {\n const {settings, injector, app} = this.platform;\n try {\n const {exists, disabled} = 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"]}
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,EA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G,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAErE,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;gBACvB,MAAM,EAAC,aAAa,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;gBAC7D,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAgB,aAAa,CAAE,CAAC;gBAClE,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;gBAE7B,aAAa,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,EAAE;oBACzD,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,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","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"]}
package/lib/esm/index.js CHANGED
@@ -10,11 +10,8 @@ export * from "./decorators/strict.js";
10
10
  export * from "./interfaces/PlatformExpressSettings.js";
11
11
  export * from "./interfaces/PlatformExpressStaticsOptions.js";
12
12
  export * from "./interfaces/interfaces.js";
13
- export * from "./middlewares/rawBodyMiddleware.js";
14
13
  export * from "./middlewares/staticsMiddleware.js";
15
- export * from "./services/PlatformExpressApplication.js";
16
14
  export * from "./services/PlatformExpressHandler.js";
17
15
  export * from "./services/PlatformExpressRequest.js";
18
16
  export * from "./services/PlatformExpressResponse.js";
19
- export * from "./services/PlatformExpressRouter.js";
20
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sCAAsC,CAAC;AACrD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC","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/rawBodyMiddleware\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformExpressApplication\";\nexport * from \"./services/PlatformExpressHandler\";\nexport * from \"./services/PlatformExpressRequest\";\nexport * from \"./services/PlatformExpressResponse\";\nexport * from \"./services/PlatformExpressRouter\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sCAAsC,CAAC;AACrD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC","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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {RouterOptions} from \"express\";\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 app?: Express.Application;\n}\n"]}
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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpressRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAmB9D;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,eAAgC;CAAG","sourcesContent":["import {PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport type Express from \"express\";\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 Request extends Express.Request {\n id: string;\n $ctx: PlatformContext;\n }\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressRequest extends PlatformRequest<Express.Request> {}\n"]}
1
+ {"version":3,"file":"PlatformExpressRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAG9D;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,eAAgC;CAAG","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"]}
@@ -1,20 +1,38 @@
1
- import Express from "express";
2
- import { PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
1
+ import Express, { RouterOptions } from "express";
2
+ import { InjectorService, PlatformAdapter, PlatformBuilder, PlatformContext, PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRequest, PlatformResponse, PlatformStaticsOptions } from "@tsed/common";
3
3
  import { Type } from "@tsed/core";
4
- import { PlatformExpressRouter } from "../services/PlatformExpressRouter";
5
4
  import { PlatformExpressHandler } from "../services/PlatformExpressHandler";
6
5
  import { PlatformExpressResponse } from "../services/PlatformExpressResponse";
7
6
  import { PlatformExpressRequest } from "../services/PlatformExpressRequest";
7
+ import { PlatformExpressStaticsOptions } from "../interfaces/PlatformExpressStaticsOptions";
8
+ declare module "express" {
9
+ interface Request {
10
+ id: string;
11
+ $ctx: PlatformContext;
12
+ }
13
+ }
14
+ declare global {
15
+ namespace TsED {
16
+ interface Router extends Express.Router {
17
+ }
18
+ interface Application extends Express.Application {
19
+ }
20
+ interface StaticsOptions extends PlatformExpressStaticsOptions {
21
+ }
22
+ interface Request extends Express.Request {
23
+ id: string;
24
+ $ctx: PlatformContext;
25
+ }
26
+ }
27
+ }
8
28
  /**
9
29
  * @platform
10
30
  * @express
11
31
  */
12
32
  export declare class PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {
13
- private platform;
33
+ #private;
34
+ protected injector: InjectorService;
14
35
  readonly providers: ({
15
- provide: typeof PlatformRouter;
16
- useClass: typeof PlatformExpressRouter;
17
- } | {
18
36
  provide: typeof PlatformHandler;
19
37
  useClass: typeof PlatformExpressHandler;
20
38
  } | {
@@ -24,7 +42,7 @@ export declare class PlatformExpress implements PlatformAdapter<Express.Applicat
24
42
  provide: typeof PlatformRequest;
25
43
  useClass: typeof PlatformExpressRequest;
26
44
  })[];
27
- constructor(platform: PlatformBuilder<Express.Application, Express.Router>);
45
+ constructor(injector: InjectorService);
28
46
  /**
29
47
  * Create new serverless application. In this mode, the component scan are disabled.
30
48
  * @param module
@@ -37,9 +55,21 @@ export declare class PlatformExpress implements PlatformAdapter<Express.Applicat
37
55
  * @param settings
38
56
  */
39
57
  static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Express.Application, Express.Router>>;
58
+ onInit(): void;
40
59
  useRouter(): this;
41
60
  beforeLoadRoutes(): Promise<void>;
42
61
  afterLoadRoutes(): Promise<void>;
43
62
  useContext(): this;
63
+ multipart(options: PlatformMulterSettings): PlatformMulter;
64
+ app(): {
65
+ app: any;
66
+ callback(): any;
67
+ };
68
+ router(routerOptions?: Partial<RouterOptions>): {
69
+ router: import("express-serve-static-core").Router;
70
+ callback(): import("express-serve-static-core").Router;
71
+ };
72
+ statics(endpoint: string, options: PlatformStaticsOptions): (request: any, response: any, next: any) => void;
73
+ bodyParser(type: "json" | "raw" | "text" | "urlencoded", additionalOptions?: any): any;
44
74
  private configureViewsEngine;
45
75
  }
@@ -10,10 +10,7 @@ export * from "./decorators/strict";
10
10
  export * from "./interfaces/PlatformExpressSettings";
11
11
  export * from "./interfaces/PlatformExpressStaticsOptions";
12
12
  export * from "./interfaces/interfaces";
13
- export * from "./middlewares/rawBodyMiddleware";
14
13
  export * from "./middlewares/staticsMiddleware";
15
- export * from "./services/PlatformExpressApplication";
16
14
  export * from "./services/PlatformExpressHandler";
17
15
  export * from "./services/PlatformExpressRequest";
18
16
  export * from "./services/PlatformExpressResponse";
19
- export * from "./services/PlatformExpressRouter";
@@ -1,9 +1,23 @@
1
1
  /// <reference types="express-serve-static-core" />
2
- import { RouterOptions } from "express";
2
+ import type { RouterOptions } from "express";
3
+ import type { OptionsJson, OptionsText, Options, OptionsUrlencoded } from "body-parser";
4
+ import type { NextHandleFunction } from "connect";
3
5
  export interface PlatformExpressSettings {
4
6
  /**
5
7
  * Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).
6
8
  */
7
9
  router?: RouterOptions;
10
+ /**
11
+ * Express application
12
+ */
8
13
  app?: Express.Application;
14
+ /**
15
+ * body parser configuration
16
+ */
17
+ bodyParser?: {
18
+ json?: (opts?: OptionsJson) => NextHandleFunction | OptionsJson;
19
+ text?: (opts?: OptionsText) => NextHandleFunction | OptionsText;
20
+ raw?: (opts?: Options) => NextHandleFunction | Options;
21
+ urlencoded?: (opts?: OptionsUrlencoded) => NextHandleFunction | OptionsUrlencoded;
22
+ };
9
23
  }
@@ -1,19 +1,5 @@
1
- import { PlatformContext, PlatformRequest } from "@tsed/common";
1
+ import { PlatformRequest } from "@tsed/common";
2
2
  import type Express from "express";
3
- declare module "express" {
4
- interface Request {
5
- id: string;
6
- $ctx: PlatformContext;
7
- }
8
- }
9
- declare global {
10
- namespace TsED {
11
- interface Request extends Express.Request {
12
- id: string;
13
- $ctx: PlatformContext;
14
- }
15
- }
16
- }
17
3
  /**
18
4
  * @platform
19
5
  * @express
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-express",
3
- "version": "6.110.2",
3
+ "version": "6.113.0",
4
4
  "description": "A TypeScript Framework on top of Express",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -56,11 +56,11 @@
56
56
  "tslib": "2.3.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@tsed/common": "6.110.2",
60
- "@tsed/core": "6.110.2",
61
- "@tsed/di": "6.110.2",
62
- "@tsed/platform-test-utils": "6.110.2",
63
- "@tsed/platform-views": "6.110.2",
59
+ "@tsed/common": "6.113.0",
60
+ "@tsed/core": "6.113.0",
61
+ "@tsed/di": "6.113.0",
62
+ "@tsed/platform-test-utils": "6.113.0",
63
+ "@tsed/platform-views": "6.113.0",
64
64
  "@types/body-parser": "1.19.2",
65
65
  "@types/compression": "1.7.2",
66
66
  "@types/cookie-parser": "1.4.2",
@@ -76,14 +76,14 @@
76
76
  "method-override": "3.0.0"
77
77
  },
78
78
  "peerDependencies": {
79
- "@tsed/common": "^6.110.2",
80
- "@tsed/core": "^6.110.2",
81
- "@tsed/di": "^6.110.2",
82
- "@tsed/json-mapper": "^6.110.2",
79
+ "@tsed/common": "^6.113.0",
80
+ "@tsed/core": "^6.113.0",
81
+ "@tsed/di": "^6.113.0",
82
+ "@tsed/json-mapper": "^6.113.0",
83
83
  "@tsed/logger": ">=6.1.1",
84
- "@tsed/openspec": "^6.110.2",
85
- "@tsed/platform-views": "^6.110.2",
86
- "@tsed/schema": "^6.110.2",
84
+ "@tsed/openspec": "^6.113.0",
85
+ "@tsed/platform-views": "^6.113.0",
86
+ "@tsed/schema": "^6.113.0",
87
87
  "@types/multer": "^1.4.5",
88
88
  "body-parser": "1.19.0"
89
89
  },
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rawBodyMiddleware = void 0;
4
- const tslib_1 = require("tslib");
5
- const bytes_1 = tslib_1.__importDefault(require("bytes"));
6
- const limit = bytes_1.default.parse("100kb");
7
- function isLimitReached(length) {
8
- return limit !== null && length !== null && length > limit;
9
- }
10
- function getContentLength(request) {
11
- const contentLength = request.get("content-length");
12
- return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;
13
- }
14
- function rawBodyMiddleware(request, response, next) {
15
- if (request.method !== "GET") {
16
- const length = getContentLength(request);
17
- if (!isLimitReached(length) && request.is(["application/x-www-form-urlencoded", "application/json"])) {
18
- request.rawBody = "";
19
- request.on("data", (chunk) => {
20
- request.rawBody += chunk;
21
- });
22
- }
23
- }
24
- next();
25
- }
26
- exports.rawBodyMiddleware = rawBodyMiddleware;
27
- //# sourceMappingURL=rawBodyMiddleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rawBodyMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/rawBodyMiddleware.ts"],"names":[],"mappings":";;;;AACA,0DAA0B;AAE1B,MAAM,KAAK,GAAG,eAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAEnC,SAAS,cAAc,CAAC,MAAqB;IAC3C,OAAO,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC;AAC7D,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAoC;IAC5D,MAAM,aAAa,GAAQ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACzD,OAAO,aAAa,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7F,CAAC;AAED,SAAgB,iBAAiB,CAAC,OAAoC,EAAE,QAAa,EAAE,IAAS;IAC9F,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE;QAC5B,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAEzC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC,mCAAmC,EAAE,kBAAkB,CAAC,CAAC,EAAE;YACpG,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC;YACrB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACnC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;YAC3B,CAAC,CAAC,CAAC;SACJ;KACF;IAED,IAAI,EAAE,CAAC;AACT,CAAC;AAbD,8CAaC","sourcesContent":["import {Request} from \"express\";\nimport bytes from \"bytes\";\n\nconst limit = bytes.parse(\"100kb\");\n\nfunction isLimitReached(length: number | null) {\n return limit !== null && length !== null && length > limit;\n}\n\nfunction getContentLength(request: Request & {rawBody: string}) {\n const contentLength: any = request.get(\"content-length\");\n return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;\n}\n\nexport function rawBodyMiddleware(request: Request & {rawBody: string}, response: any, next: any) {\n if (request.method !== \"GET\") {\n const length = getContentLength(request);\n\n if (!isLimitReached(length) && request.is([\"application/x-www-form-urlencoded\", \"application/json\"])) {\n request.rawBody = \"\";\n request.on(\"data\", (chunk: string) => {\n request.rawBody += chunk;\n });\n }\n }\n\n next();\n}\n"]}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformExpressApplication = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@tsed/common");
6
- const express_1 = tslib_1.__importDefault(require("express"));
7
- const PlatformExpressRouter_1 = require("./PlatformExpressRouter");
8
- /**
9
- * @platform
10
- * @express
11
- */
12
- let PlatformExpressApplication = class PlatformExpressApplication extends PlatformExpressRouter_1.PlatformExpressRouter {
13
- constructor(platformHandler, configuration) {
14
- super(platformHandler, configuration, {
15
- mergeParams: true
16
- });
17
- this.rawApp = configuration.get("express.app") || (0, express_1.default)();
18
- }
19
- getApp() {
20
- return this.rawApp;
21
- }
22
- callback() {
23
- return this.rawApp;
24
- }
25
- };
26
- PlatformExpressApplication = tslib_1.__decorate([
27
- tslib_1.__param(0, (0, common_1.Inject)()),
28
- tslib_1.__param(1, (0, common_1.Configuration)()),
29
- tslib_1.__metadata("design:paramtypes", [common_1.PlatformHandler, Object])
30
- ], PlatformExpressApplication);
31
- exports.PlatformExpressApplication = PlatformExpressApplication;
32
- //# sourceMappingURL=PlatformExpressApplication.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformExpressApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressApplication.ts"],"names":[],"mappings":";;;;AAAA,yCAAyF;AACzF,8DAA8B;AAE9B,mEAA8D;AAU9D;;;GAGG;AACH,IAAa,0BAA0B,GAAvC,MAAa,0BAA2B,SAAQ,6CAAqB;IAKnE,YAAsB,eAAgC,EAAmB,aAA4B;QACnG,KAAK,CAAC,eAAe,EAAE,aAAa,EAAE;YACpC,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,IAAA,iBAAO,GAAE,CAAC;IAC9D,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF,CAAA;AApBY,0BAA0B;IAKxB,mBAAA,IAAA,eAAM,GAAE,CAAA;IAAoC,mBAAA,IAAA,sBAAa,GAAE,CAAA;6CAAjC,wBAAe;GAL3C,0BAA0B,CAoBtC;AApBY,gEAA0B","sourcesContent":["import {Configuration, Inject, PlatformApplication, PlatformHandler} from \"@tsed/common\";\nimport Express from \"express\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {PlatformExpressRouter} from \"./PlatformExpressRouter\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressApplication extends PlatformExpressRouter implements PlatformApplication<Express.Application, Express.Router> {\n app: Express.Application;\n rawApp: Express.Application;\n rawRouter: Express.Router;\n\n constructor(@Inject() platformHandler: PlatformHandler, @Configuration() configuration: Configuration) {\n super(platformHandler, configuration, {\n mergeParams: true\n });\n\n this.rawApp = configuration.get(\"express.app\") || Express();\n }\n\n getApp() {\n return this.rawApp;\n }\n\n callback() {\n return this.rawApp;\n }\n}\n"]}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformExpressRouter = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@tsed/common");
6
- const di_1 = require("@tsed/di");
7
- const express_1 = tslib_1.__importDefault(require("express"));
8
- const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
9
- /**
10
- * @platform
11
- * @express
12
- */
13
- let PlatformExpressRouter = class PlatformExpressRouter extends common_1.PlatformRouter {
14
- constructor(platform, configuration, routerOptions = {}) {
15
- var _a;
16
- super(platform);
17
- const options = Object.assign({
18
- mergeParams: true
19
- }, ((_a = configuration.express) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
20
- this.rawRouter = this.raw = express_1.default.Router(options);
21
- }
22
- statics(endpoint, options) {
23
- const { root, ...props } = options;
24
- this.use(endpoint, (0, staticsMiddleware_1.staticsMiddleware)(root, props));
25
- return this;
26
- }
27
- };
28
- PlatformExpressRouter = tslib_1.__decorate([
29
- tslib_1.__param(1, (0, di_1.Configuration)()),
30
- tslib_1.__param(2, (0, di_1.Inject)(common_1.PLATFORM_ROUTER_OPTIONS)),
31
- tslib_1.__metadata("design:paramtypes", [common_1.PlatformHandler, Object, Object])
32
- ], PlatformExpressRouter);
33
- exports.PlatformExpressRouter = PlatformExpressRouter;
34
- //# sourceMappingURL=PlatformExpressRouter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformExpressRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressRouter.ts"],"names":[],"mappings":";;;;AAAA,yCAA8G;AAC9G,iCAA+C;AAC/C,8DAA8B;AAE9B,wEAAmE;AAQnE;;;GAGG;AACH,IAAa,qBAAqB,GAAlC,MAAa,qBAAsB,SAAQ,uBAA8B;IACvE,YACE,QAAyB,EACR,aAA4B,EACZ,gBAAwC,EAAE;;QAE3E,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAC3B;YACE,WAAW,EAAE,IAAI;SAClB,EACD,CAAA,MAAA,aAAa,CAAC,OAAO,0CAAE,MAAM,KAAI,EAAE,EACnC,aAAa,CACd,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,GAAG,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,MAAM,EAAC,IAAI,EAAE,GAAG,KAAK,EAAC,GAAG,OAAO,CAAC;QAEjC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAA,qCAAiB,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAEnD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzBY,qBAAqB;IAG7B,mBAAA,IAAA,kBAAa,GAAE,CAAA;IACf,mBAAA,IAAA,WAAM,EAAC,gCAAuB,CAAC,CAAA;6CAFtB,wBAAe;GAFhB,qBAAqB,CAyBjC;AAzBY,sDAAqB","sourcesContent":["import {PLATFORM_ROUTER_OPTIONS, PlatformHandler, PlatformRouter, PlatformStaticsOptions} from \"@tsed/common\";\nimport {Configuration, Inject} from \"@tsed/di\";\nimport Express from \"express\";\nimport {RouterOptions} from \"express\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\n\ndeclare global {\n namespace TsED {\n export interface Router extends Express.Router {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressRouter extends PlatformRouter<Express.Router> {\n constructor(\n platform: PlatformHandler,\n @Configuration() configuration: Configuration,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: Partial<RouterOptions> = {}\n ) {\n super(platform);\n\n const options = Object.assign(\n {\n mergeParams: true\n },\n configuration.express?.router || {},\n routerOptions\n );\n this.rawRouter = this.raw = Express.Router(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n this.use(endpoint, staticsMiddleware(root, props));\n\n return this;\n }\n}\n"]}
@@ -1,22 +0,0 @@
1
- import bytes from "bytes";
2
- const limit = bytes.parse("100kb");
3
- function isLimitReached(length) {
4
- return limit !== null && length !== null && length > limit;
5
- }
6
- function getContentLength(request) {
7
- const contentLength = request.get("content-length");
8
- return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;
9
- }
10
- export function rawBodyMiddleware(request, response, next) {
11
- if (request.method !== "GET") {
12
- const length = getContentLength(request);
13
- if (!isLimitReached(length) && request.is(["application/x-www-form-urlencoded", "application/json"])) {
14
- request.rawBody = "";
15
- request.on("data", (chunk) => {
16
- request.rawBody += chunk;
17
- });
18
- }
19
- }
20
- next();
21
- }
22
- //# sourceMappingURL=rawBodyMiddleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rawBodyMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/rawBodyMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAEnC,SAAS,cAAc,CAAC,MAAqB;IAC3C,OAAO,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC;AAC7D,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAoC;IAC5D,MAAM,aAAa,GAAQ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACzD,OAAO,aAAa,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAoC,EAAE,QAAa,EAAE,IAAS;IAC9F,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE;QAC5B,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAEzC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC,mCAAmC,EAAE,kBAAkB,CAAC,CAAC,EAAE;YACpG,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC;YACrB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACnC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;YAC3B,CAAC,CAAC,CAAC;SACJ;KACF;IAED,IAAI,EAAE,CAAC;AACT,CAAC","sourcesContent":["import {Request} from \"express\";\nimport bytes from \"bytes\";\n\nconst limit = bytes.parse(\"100kb\");\n\nfunction isLimitReached(length: number | null) {\n return limit !== null && length !== null && length > limit;\n}\n\nfunction getContentLength(request: Request & {rawBody: string}) {\n const contentLength: any = request.get(\"content-length\");\n return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;\n}\n\nexport function rawBodyMiddleware(request: Request & {rawBody: string}, response: any, next: any) {\n if (request.method !== \"GET\") {\n const length = getContentLength(request);\n\n if (!isLimitReached(length) && request.is([\"application/x-www-form-urlencoded\", \"application/json\"])) {\n request.rawBody = \"\";\n request.on(\"data\", (chunk: string) => {\n request.rawBody += chunk;\n });\n }\n }\n\n next();\n}\n"]}
@@ -1,29 +0,0 @@
1
- import { __decorate, __metadata, __param } from "tslib";
2
- import { Configuration, Inject, PlatformHandler } from "@tsed/common";
3
- import Express from "express";
4
- import { PlatformExpressRouter } from "./PlatformExpressRouter.js";
5
- /**
6
- * @platform
7
- * @express
8
- */
9
- let PlatformExpressApplication = class PlatformExpressApplication extends PlatformExpressRouter {
10
- constructor(platformHandler, configuration) {
11
- super(platformHandler, configuration, {
12
- mergeParams: true
13
- });
14
- this.rawApp = configuration.get("express.app") || Express();
15
- }
16
- getApp() {
17
- return this.rawApp;
18
- }
19
- callback() {
20
- return this.rawApp;
21
- }
22
- };
23
- PlatformExpressApplication = __decorate([
24
- __param(0, Inject()),
25
- __param(1, Configuration()),
26
- __metadata("design:paramtypes", [PlatformHandler, Object])
27
- ], PlatformExpressApplication);
28
- export { PlatformExpressApplication };
29
- //# sourceMappingURL=PlatformExpressApplication.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformExpressApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressApplication.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,MAAM,EAAuB,eAAe,EAAC,MAAM,cAAc,CAAC;AACzF,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AAU9D;;;GAGG;AACH,IAAa,0BAA0B,GAAvC,MAAa,0BAA2B,SAAQ,qBAAqB;IAKnE,YAAsB,eAAgC,EAAmB,aAA4B;QACnG,KAAK,CAAC,eAAe,EAAE,aAAa,EAAE;YACpC,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,OAAO,EAAE,CAAC;IAC9D,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF,CAAA;AApBY,0BAA0B;IAKxB,WAAA,MAAM,EAAE,CAAA;IAAoC,WAAA,aAAa,EAAE,CAAA;qCAAjC,eAAe;GAL3C,0BAA0B,CAoBtC;SApBY,0BAA0B","sourcesContent":["import {Configuration, Inject, PlatformApplication, PlatformHandler} from \"@tsed/common\";\nimport Express from \"express\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {PlatformExpressRouter} from \"./PlatformExpressRouter\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressApplication extends PlatformExpressRouter implements PlatformApplication<Express.Application, Express.Router> {\n app: Express.Application;\n rawApp: Express.Application;\n rawRouter: Express.Router;\n\n constructor(@Inject() platformHandler: PlatformHandler, @Configuration() configuration: Configuration) {\n super(platformHandler, configuration, {\n mergeParams: true\n });\n\n this.rawApp = configuration.get(\"express.app\") || Express();\n }\n\n getApp() {\n return this.rawApp;\n }\n\n callback() {\n return this.rawApp;\n }\n}\n"]}
@@ -1,31 +0,0 @@
1
- import { __decorate, __metadata, __param } from "tslib";
2
- import { PLATFORM_ROUTER_OPTIONS, PlatformHandler, PlatformRouter } from "@tsed/common";
3
- import { Configuration, Inject } from "@tsed/di";
4
- import Express from "express";
5
- import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
6
- /**
7
- * @platform
8
- * @express
9
- */
10
- let PlatformExpressRouter = class PlatformExpressRouter extends PlatformRouter {
11
- constructor(platform, configuration, routerOptions = {}) {
12
- var _a;
13
- super(platform);
14
- const options = Object.assign({
15
- mergeParams: true
16
- }, ((_a = configuration.express) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
17
- this.rawRouter = this.raw = Express.Router(options);
18
- }
19
- statics(endpoint, options) {
20
- const { root, ...props } = options;
21
- this.use(endpoint, staticsMiddleware(root, props));
22
- return this;
23
- }
24
- };
25
- PlatformExpressRouter = __decorate([
26
- __param(1, Configuration()),
27
- __param(2, Inject(PLATFORM_ROUTER_OPTIONS)),
28
- __metadata("design:paramtypes", [PlatformHandler, Object, Object])
29
- ], PlatformExpressRouter);
30
- export { PlatformExpressRouter };
31
- //# sourceMappingURL=PlatformExpressRouter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformExpressRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressRouter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,uBAAuB,EAAE,eAAe,EAAE,cAAc,EAAyB,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAC,aAAa,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAC/C,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AAQnE;;;GAGG;AACH,IAAa,qBAAqB,GAAlC,MAAa,qBAAsB,SAAQ,cAA8B;IACvE,YACE,QAAyB,EACR,aAA4B,EACZ,gBAAwC,EAAE;;QAE3E,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAC3B;YACE,WAAW,EAAE,IAAI;SAClB,EACD,CAAA,MAAA,aAAa,CAAC,OAAO,0CAAE,MAAM,KAAI,EAAE,EACnC,aAAa,CACd,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,MAAM,EAAC,IAAI,EAAE,GAAG,KAAK,EAAC,GAAG,OAAO,CAAC;QAEjC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAEnD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzBY,qBAAqB;IAG7B,WAAA,aAAa,EAAE,CAAA;IACf,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;qCAFtB,eAAe;GAFhB,qBAAqB,CAyBjC;SAzBY,qBAAqB","sourcesContent":["import {PLATFORM_ROUTER_OPTIONS, PlatformHandler, PlatformRouter, PlatformStaticsOptions} from \"@tsed/common\";\nimport {Configuration, Inject} from \"@tsed/di\";\nimport Express from \"express\";\nimport {RouterOptions} from \"express\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\n\ndeclare global {\n namespace TsED {\n export interface Router extends Express.Router {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressRouter extends PlatformRouter<Express.Router> {\n constructor(\n platform: PlatformHandler,\n @Configuration() configuration: Configuration,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: Partial<RouterOptions> = {}\n ) {\n super(platform);\n\n const options = Object.assign(\n {\n mergeParams: true\n },\n configuration.express?.router || {},\n routerOptions\n );\n this.rawRouter = this.raw = Express.Router(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n this.use(endpoint, staticsMiddleware(root, props));\n\n return this;\n }\n}\n"]}
@@ -1,4 +0,0 @@
1
- import { Request } from "express";
2
- export declare function rawBodyMiddleware(request: Request & {
3
- rawBody: string;
4
- }, response: any, next: any): void;
@@ -1,24 +0,0 @@
1
- import { Configuration, PlatformApplication, PlatformHandler } from "@tsed/common";
2
- import Express from "express";
3
- import { PlatformExpressStaticsOptions } from "../interfaces/PlatformExpressStaticsOptions";
4
- import { PlatformExpressRouter } from "./PlatformExpressRouter";
5
- declare global {
6
- namespace TsED {
7
- interface Application extends Express.Application {
8
- }
9
- interface StaticsOptions extends PlatformExpressStaticsOptions {
10
- }
11
- }
12
- }
13
- /**
14
- * @platform
15
- * @express
16
- */
17
- export declare class PlatformExpressApplication extends PlatformExpressRouter implements PlatformApplication<Express.Application, Express.Router> {
18
- app: Express.Application;
19
- rawApp: Express.Application;
20
- rawRouter: Express.Router;
21
- constructor(platformHandler: PlatformHandler, configuration: Configuration);
22
- getApp(): Express.Application;
23
- callback(): Express.Application;
24
- }
@@ -1,18 +0,0 @@
1
- import { PlatformHandler, PlatformRouter, PlatformStaticsOptions } from "@tsed/common";
2
- import { Configuration } from "@tsed/di";
3
- import Express from "express";
4
- import { RouterOptions } from "express";
5
- declare global {
6
- namespace TsED {
7
- interface Router extends Express.Router {
8
- }
9
- }
10
- }
11
- /**
12
- * @platform
13
- * @express
14
- */
15
- export declare class PlatformExpressRouter extends PlatformRouter<Express.Router> {
16
- constructor(platform: PlatformHandler, configuration: Configuration, routerOptions?: Partial<RouterOptions>);
17
- statics(endpoint: string, options: PlatformStaticsOptions): this;
18
- }