@tsed/platform-express 7.0.0-beta.13 → 7.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/PlatformExpress.js +63 -54
- package/lib/cjs/components/PlatformExpress.js.map +1 -1
- package/lib/cjs/index.js +0 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/components/PlatformExpress.js +64 -55
- package/lib/esm/components/PlatformExpress.js.map +1 -1
- package/lib/esm/index.js +0 -7
- package/lib/esm/index.js.map +1 -1
- package/lib/types/components/PlatformExpress.d.ts +11 -26
- package/lib/types/index.d.ts +0 -7
- package/package.json +16 -14
- package/readme.md +1 -1
- package/lib/cjs/decorators/caseSensitive.js +0 -31
- package/lib/cjs/decorators/caseSensitive.js.map +0 -1
- package/lib/cjs/decorators/mergeParams.js +0 -31
- package/lib/cjs/decorators/mergeParams.js.map +0 -1
- package/lib/cjs/decorators/routerSettings.js +0 -32
- package/lib/cjs/decorators/routerSettings.js.map +0 -1
- package/lib/cjs/decorators/strict.js +0 -31
- package/lib/cjs/decorators/strict.js.map +0 -1
- package/lib/cjs/services/PlatformExpressHandler.js +0 -31
- package/lib/cjs/services/PlatformExpressHandler.js.map +0 -1
- package/lib/cjs/services/PlatformExpressRequest.js +0 -12
- package/lib/cjs/services/PlatformExpressRequest.js.map +0 -1
- package/lib/cjs/services/PlatformExpressResponse.js +0 -12
- package/lib/cjs/services/PlatformExpressResponse.js.map +0 -1
- package/lib/esm/decorators/caseSensitive.js +0 -27
- package/lib/esm/decorators/caseSensitive.js.map +0 -1
- package/lib/esm/decorators/mergeParams.js +0 -27
- package/lib/esm/decorators/mergeParams.js.map +0 -1
- package/lib/esm/decorators/routerSettings.js +0 -28
- package/lib/esm/decorators/routerSettings.js.map +0 -1
- package/lib/esm/decorators/strict.js +0 -27
- package/lib/esm/decorators/strict.js.map +0 -1
- package/lib/esm/services/PlatformExpressHandler.js +0 -27
- package/lib/esm/services/PlatformExpressHandler.js.map +0 -1
- package/lib/esm/services/PlatformExpressRequest.js +0 -8
- package/lib/esm/services/PlatformExpressRequest.js.map +0 -1
- package/lib/esm/services/PlatformExpressResponse.js +0 -8
- package/lib/esm/services/PlatformExpressResponse.js.map +0 -1
- package/lib/types/decorators/caseSensitive.d.ts +0 -23
- package/lib/types/decorators/mergeParams.d.ts +0 -23
- package/lib/types/decorators/routerSettings.d.ts +0 -24
- package/lib/types/decorators/strict.d.ts +0 -23
- package/lib/types/services/PlatformExpressHandler.d.ts +0 -9
- package/lib/types/services/PlatformExpressRequest.d.ts +0 -8
- package/lib/types/services/PlatformExpressResponse.d.ts +0 -14
|
@@ -4,32 +4,18 @@ exports.PlatformExpress = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@tsed/common");
|
|
6
6
|
const core_1 = require("@tsed/core");
|
|
7
|
+
const platform_router_1 = require("@tsed/platform-router");
|
|
7
8
|
const express_1 = tslib_1.__importDefault(require("express"));
|
|
9
|
+
const on_finished_1 = tslib_1.__importDefault(require("on-finished"));
|
|
8
10
|
const util_1 = require("util");
|
|
9
11
|
const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
|
|
10
|
-
const PlatformExpressHandler_1 = require("../services/PlatformExpressHandler");
|
|
11
|
-
const PlatformExpressRequest_1 = require("../services/PlatformExpressRequest");
|
|
12
|
-
const PlatformExpressResponse_1 = require("../services/PlatformExpressResponse");
|
|
13
12
|
/**
|
|
14
13
|
* @platform
|
|
15
14
|
* @express
|
|
16
15
|
*/
|
|
17
16
|
class PlatformExpress {
|
|
18
17
|
injector;
|
|
19
|
-
providers = [
|
|
20
|
-
{
|
|
21
|
-
provide: common_1.PlatformHandler,
|
|
22
|
-
useClass: PlatformExpressHandler_1.PlatformExpressHandler
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
provide: common_1.PlatformResponse,
|
|
26
|
-
useClass: PlatformExpressResponse_1.PlatformExpressResponse
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
provide: common_1.PlatformRequest,
|
|
30
|
-
useClass: PlatformExpressRequest_1.PlatformExpressRequest
|
|
31
|
-
}
|
|
32
|
-
];
|
|
18
|
+
providers = [];
|
|
33
19
|
#multer;
|
|
34
20
|
constructor(injector) {
|
|
35
21
|
this.injector = injector;
|
|
@@ -68,43 +54,84 @@ class PlatformExpress {
|
|
|
68
54
|
return true;
|
|
69
55
|
}));
|
|
70
56
|
}
|
|
71
|
-
useRouter() {
|
|
72
|
-
const { logger } = this.injector;
|
|
73
|
-
const app = this.injector.get(common_1.PlatformApplication);
|
|
74
|
-
logger.debug("Mount app router");
|
|
75
|
-
app.getApp().use(app.getRouter());
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
57
|
async beforeLoadRoutes() {
|
|
79
58
|
const injector = this.injector;
|
|
80
59
|
const app = this.injector.get(common_1.PlatformApplication);
|
|
81
60
|
// disable x-powered-by header
|
|
82
61
|
injector.settings.get("env") === core_1.Env.PROD && app.getApp().disable("x-powered-by");
|
|
83
62
|
await this.configureViewsEngine();
|
|
63
|
+
this.useContext();
|
|
84
64
|
}
|
|
85
65
|
async afterLoadRoutes() {
|
|
86
|
-
const injector = this.injector;
|
|
87
66
|
const app = this.injector.get(common_1.PlatformApplication);
|
|
67
|
+
const platformExceptions = this.injector.get(common_1.PlatformExceptions);
|
|
88
68
|
// NOT FOUND
|
|
89
69
|
app.use((req, res, next) => {
|
|
90
|
-
|
|
70
|
+
const $ctx = (0, common_1.getContext)();
|
|
71
|
+
!$ctx.isDone() && platformExceptions.resourceNotFound($ctx);
|
|
91
72
|
});
|
|
92
73
|
// EXCEPTION FILTERS
|
|
93
74
|
app.use((err, req, res, next) => {
|
|
94
|
-
|
|
75
|
+
const $ctx = (0, common_1.getContext)();
|
|
76
|
+
!$ctx.isDone() && platformExceptions.catch(err, $ctx);
|
|
95
77
|
});
|
|
96
78
|
}
|
|
79
|
+
mapLayers(layers) {
|
|
80
|
+
const app = this.getPlatformApplication();
|
|
81
|
+
const rawApp = app.getApp();
|
|
82
|
+
layers.forEach((layer) => {
|
|
83
|
+
switch (layer.method) {
|
|
84
|
+
case "statics":
|
|
85
|
+
rawApp.use(layer.path, this.statics(layer.path, layer.opts));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
rawApp[layer.method](...layer.getArgs());
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
mapHandler(handler, metadata) {
|
|
92
|
+
switch (metadata.type) {
|
|
93
|
+
case platform_router_1.PlatformHandlerType.RAW_ERR_FN:
|
|
94
|
+
return (error, req, res, next) => handler(error, req, res, (0, common_1.bindContext)(next));
|
|
95
|
+
case platform_router_1.PlatformHandlerType.RAW_FN:
|
|
96
|
+
return (req, res, next) => handler(req, res, (0, common_1.bindContext)(next));
|
|
97
|
+
case platform_router_1.PlatformHandlerType.ERR_MIDDLEWARE:
|
|
98
|
+
return async (error, req, res, next) => {
|
|
99
|
+
const $ctx = (0, common_1.getContext)();
|
|
100
|
+
$ctx.next = next;
|
|
101
|
+
$ctx.error = error;
|
|
102
|
+
await handler($ctx);
|
|
103
|
+
};
|
|
104
|
+
default:
|
|
105
|
+
return async (req, res, next) => {
|
|
106
|
+
const $ctx = (0, common_1.getContext)();
|
|
107
|
+
$ctx.next = next;
|
|
108
|
+
await handler($ctx);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
97
112
|
useContext() {
|
|
98
|
-
const
|
|
99
|
-
logger.debug("Mount app context");
|
|
113
|
+
const app = this.getPlatformApplication();
|
|
100
114
|
const invoke = (0, common_1.createContext)(this.injector);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
115
|
+
app.use(async (request, response, next) => {
|
|
116
|
+
const $ctx = await invoke({
|
|
117
|
+
request,
|
|
118
|
+
response
|
|
119
|
+
});
|
|
120
|
+
await $ctx.start();
|
|
121
|
+
(0, on_finished_1.default)(response, () => $ctx.finish());
|
|
122
|
+
return $ctx.runInContext(next);
|
|
105
123
|
});
|
|
106
124
|
return this;
|
|
107
125
|
}
|
|
126
|
+
app() {
|
|
127
|
+
const app = this.injector.settings.get("express.app") || (0, express_1.default)();
|
|
128
|
+
return {
|
|
129
|
+
app,
|
|
130
|
+
callback() {
|
|
131
|
+
return app;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
108
135
|
multipart(options) {
|
|
109
136
|
const m = this.#multer(options);
|
|
110
137
|
const makePromise = (multer, name) => {
|
|
@@ -124,27 +151,6 @@ class PlatformExpress {
|
|
|
124
151
|
makePromise(m, "single");
|
|
125
152
|
return m;
|
|
126
153
|
}
|
|
127
|
-
app() {
|
|
128
|
-
const app = this.injector.settings.get("express.app") || (0, express_1.default)();
|
|
129
|
-
return {
|
|
130
|
-
app,
|
|
131
|
-
callback() {
|
|
132
|
-
return app;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
router(routerOptions = {}) {
|
|
137
|
-
const options = Object.assign({
|
|
138
|
-
mergeParams: true
|
|
139
|
-
}, this.injector.settings.get("express.router", {}), routerOptions);
|
|
140
|
-
const router = express_1.default.Router(options);
|
|
141
|
-
return {
|
|
142
|
-
router,
|
|
143
|
-
callback() {
|
|
144
|
-
return router;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
154
|
statics(endpoint, options) {
|
|
149
155
|
const { root, ...props } = options;
|
|
150
156
|
return (0, staticsMiddleware_1.staticsMiddleware)(root, props);
|
|
@@ -167,6 +173,9 @@ class PlatformExpress {
|
|
|
167
173
|
}
|
|
168
174
|
return parser({ ...options, ...additionalOptions });
|
|
169
175
|
}
|
|
176
|
+
getPlatformApplication() {
|
|
177
|
+
return this.injector.get(common_1.PlatformApplication);
|
|
178
|
+
}
|
|
170
179
|
async configureViewsEngine() {
|
|
171
180
|
const injector = this.injector;
|
|
172
181
|
const app = this.injector.get(common_1.PlatformApplication);
|
|
@@ -1 +1 @@
|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IAAI;YACF,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,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,gEAAa,sBAAsB,GAAC,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;AAhOD,0CAgOC","sourcesContent":["import {\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 {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\nimport Express, {RouterOptions} from \"express\";\nimport type multer from \"multer\";\nimport {promisify} from \"util\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformExpressHandler} from \"../services/PlatformExpressHandler\";\nimport {PlatformExpressRequest} from \"../services/PlatformExpressRequest\";\nimport {PlatformExpressResponse} from \"../services/PlatformExpressResponse\";\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 const middlewares = this.injector.settings.get(\"middlewares\", []);\n\n this.injector.settings.set(\n \"middlewares\",\n 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\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.get(\"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"]}
|
|
1
|
+
{"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;AAAA,yCA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AE,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;AAxOD,0CAwOC","sourcesContent":["import {\n bindContext,\n createContext,\n getContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport {PlatformHandlerMetadata, PlatformHandlerType, PlatformLayer} from \"@tsed/platform-router\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\nimport Express from \"express\";\nimport type multer from \"multer\";\nimport onFinished from \"on-finished\";\nimport {promisify} from \"util\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\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> {\n readonly providers = [];\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>(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>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n onInit() {\n const middlewares = this.injector.settings.get(\"middlewares\", []);\n\n this.injector.settings.set(\n \"middlewares\",\n 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\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 this.useContext();\n }\n\n async afterLoadRoutes() {\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n const platformExceptions = this.injector.get<PlatformExceptions>(PlatformExceptions)!;\n\n // NOT FOUND\n app.use((req: any, res: any, next: any) => {\n const $ctx = getContext()!;\n !$ctx.isDone() && platformExceptions.resourceNotFound($ctx);\n });\n\n // EXCEPTION FILTERS\n app.use((err: any, req: any, res: any, next: any) => {\n const $ctx = getContext()!;\n\n !$ctx.isDone() && platformExceptions.catch(err, $ctx);\n });\n }\n\n mapLayers(layers: PlatformLayer[]) {\n const app = this.getPlatformApplication();\n const rawApp: any = app.getApp();\n\n layers.forEach((layer) => {\n switch (layer.method) {\n case \"statics\":\n rawApp.use(layer.path, this.statics(layer.path as string, layer.opts as any));\n return;\n }\n\n rawApp[layer.method](...layer.getArgs());\n });\n }\n\n mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {\n switch (metadata.type) {\n case PlatformHandlerType.RAW_ERR_FN:\n return (error: unknown, req: any, res: any, next: any) => handler(error, req, res, bindContext(next));\n case PlatformHandlerType.RAW_FN:\n return (req: any, res: any, next: any) => handler(req, res, bindContext(next));\n case PlatformHandlerType.ERR_MIDDLEWARE:\n return async (error: unknown, req: any, res: any, next: any) => {\n const $ctx = getContext<PlatformContext>()!;\n $ctx.next = next;\n $ctx.error = error;\n\n await handler($ctx);\n };\n default:\n return async (req: any, res: any, next: any) => {\n const $ctx = getContext<PlatformContext>()!;\n $ctx.next = next;\n\n await handler($ctx);\n };\n }\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n const invoke = createContext(this.injector);\n\n app.use(async (request: any, response: any, next: any) => {\n const $ctx = await invoke({\n request,\n response\n });\n\n await $ctx.start();\n\n onFinished(response, () => $ctx.finish());\n\n return $ctx.runInContext(next);\n });\n\n return this;\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 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 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 getPlatformApplication() {\n return this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\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
|
@@ -6,15 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
tslib_1.__exportStar(require("./exports"), exports);
|
|
8
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
9
|
tslib_1.__exportStar(require("./interfaces/PlatformExpressSettings"), exports);
|
|
14
10
|
tslib_1.__exportStar(require("./interfaces/PlatformExpressStaticsOptions"), exports);
|
|
15
11
|
tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
|
|
16
12
|
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
13
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,uEAA6C;AAC7C
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,uEAA6C;AAC7C,+EAAqD;AACrD,qFAA2D;AAC3D,kEAAwC;AACxC,0EAAgD","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformExpress\";\nexport * from \"./interfaces/PlatformExpressSettings\";\nexport * from \"./interfaces/PlatformExpressStaticsOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\n"]}
|
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions
|
|
1
|
+
import { bindContext, createContext, getContext, PlatformApplication, PlatformBuilder, PlatformExceptions } from "@tsed/common";
|
|
2
2
|
import { Env, isFunction, nameOf } from "@tsed/core";
|
|
3
|
+
import { PlatformHandlerType } from "@tsed/platform-router";
|
|
3
4
|
import Express from "express";
|
|
5
|
+
import onFinished from "on-finished";
|
|
4
6
|
import { promisify } from "util";
|
|
5
7
|
import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
|
|
6
|
-
import { PlatformExpressHandler } from "../services/PlatformExpressHandler.js";
|
|
7
|
-
import { PlatformExpressRequest } from "../services/PlatformExpressRequest.js";
|
|
8
|
-
import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
|
|
9
8
|
/**
|
|
10
9
|
* @platform
|
|
11
10
|
* @express
|
|
12
11
|
*/
|
|
13
12
|
export class PlatformExpress {
|
|
14
13
|
injector;
|
|
15
|
-
providers = [
|
|
16
|
-
{
|
|
17
|
-
provide: PlatformHandler,
|
|
18
|
-
useClass: PlatformExpressHandler
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
provide: PlatformResponse,
|
|
22
|
-
useClass: PlatformExpressResponse
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
provide: PlatformRequest,
|
|
26
|
-
useClass: PlatformExpressRequest
|
|
27
|
-
}
|
|
28
|
-
];
|
|
14
|
+
providers = [];
|
|
29
15
|
#multer;
|
|
30
16
|
constructor(injector) {
|
|
31
17
|
this.injector = injector;
|
|
@@ -64,43 +50,84 @@ export class PlatformExpress {
|
|
|
64
50
|
return true;
|
|
65
51
|
}));
|
|
66
52
|
}
|
|
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
53
|
async beforeLoadRoutes() {
|
|
75
54
|
const injector = this.injector;
|
|
76
55
|
const app = this.injector.get(PlatformApplication);
|
|
77
56
|
// disable x-powered-by header
|
|
78
57
|
injector.settings.get("env") === Env.PROD && app.getApp().disable("x-powered-by");
|
|
79
58
|
await this.configureViewsEngine();
|
|
59
|
+
this.useContext();
|
|
80
60
|
}
|
|
81
61
|
async afterLoadRoutes() {
|
|
82
|
-
const injector = this.injector;
|
|
83
62
|
const app = this.injector.get(PlatformApplication);
|
|
63
|
+
const platformExceptions = this.injector.get(PlatformExceptions);
|
|
84
64
|
// NOT FOUND
|
|
85
65
|
app.use((req, res, next) => {
|
|
86
|
-
|
|
66
|
+
const $ctx = getContext();
|
|
67
|
+
!$ctx.isDone() && platformExceptions.resourceNotFound($ctx);
|
|
87
68
|
});
|
|
88
69
|
// EXCEPTION FILTERS
|
|
89
70
|
app.use((err, req, res, next) => {
|
|
90
|
-
|
|
71
|
+
const $ctx = getContext();
|
|
72
|
+
!$ctx.isDone() && platformExceptions.catch(err, $ctx);
|
|
91
73
|
});
|
|
92
74
|
}
|
|
75
|
+
mapLayers(layers) {
|
|
76
|
+
const app = this.getPlatformApplication();
|
|
77
|
+
const rawApp = app.getApp();
|
|
78
|
+
layers.forEach((layer) => {
|
|
79
|
+
switch (layer.method) {
|
|
80
|
+
case "statics":
|
|
81
|
+
rawApp.use(layer.path, this.statics(layer.path, layer.opts));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
rawApp[layer.method](...layer.getArgs());
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
mapHandler(handler, metadata) {
|
|
88
|
+
switch (metadata.type) {
|
|
89
|
+
case PlatformHandlerType.RAW_ERR_FN:
|
|
90
|
+
return (error, req, res, next) => handler(error, req, res, bindContext(next));
|
|
91
|
+
case PlatformHandlerType.RAW_FN:
|
|
92
|
+
return (req, res, next) => handler(req, res, bindContext(next));
|
|
93
|
+
case PlatformHandlerType.ERR_MIDDLEWARE:
|
|
94
|
+
return async (error, req, res, next) => {
|
|
95
|
+
const $ctx = getContext();
|
|
96
|
+
$ctx.next = next;
|
|
97
|
+
$ctx.error = error;
|
|
98
|
+
await handler($ctx);
|
|
99
|
+
};
|
|
100
|
+
default:
|
|
101
|
+
return async (req, res, next) => {
|
|
102
|
+
const $ctx = getContext();
|
|
103
|
+
$ctx.next = next;
|
|
104
|
+
await handler($ctx);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
93
108
|
useContext() {
|
|
94
|
-
const
|
|
95
|
-
logger.debug("Mount app context");
|
|
109
|
+
const app = this.getPlatformApplication();
|
|
96
110
|
const invoke = createContext(this.injector);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
app.use(async (request, response, next) => {
|
|
112
|
+
const $ctx = await invoke({
|
|
113
|
+
request,
|
|
114
|
+
response
|
|
115
|
+
});
|
|
116
|
+
await $ctx.start();
|
|
117
|
+
onFinished(response, () => $ctx.finish());
|
|
118
|
+
return $ctx.runInContext(next);
|
|
101
119
|
});
|
|
102
120
|
return this;
|
|
103
121
|
}
|
|
122
|
+
app() {
|
|
123
|
+
const app = this.injector.settings.get("express.app") || Express();
|
|
124
|
+
return {
|
|
125
|
+
app,
|
|
126
|
+
callback() {
|
|
127
|
+
return app;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
104
131
|
multipart(options) {
|
|
105
132
|
const m = this.#multer(options);
|
|
106
133
|
const makePromise = (multer, name) => {
|
|
@@ -120,27 +147,6 @@ export class PlatformExpress {
|
|
|
120
147
|
makePromise(m, "single");
|
|
121
148
|
return m;
|
|
122
149
|
}
|
|
123
|
-
app() {
|
|
124
|
-
const app = this.injector.settings.get("express.app") || Express();
|
|
125
|
-
return {
|
|
126
|
-
app,
|
|
127
|
-
callback() {
|
|
128
|
-
return app;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
router(routerOptions = {}) {
|
|
133
|
-
const options = Object.assign({
|
|
134
|
-
mergeParams: true
|
|
135
|
-
}, this.injector.settings.get("express.router", {}), routerOptions);
|
|
136
|
-
const router = Express.Router(options);
|
|
137
|
-
return {
|
|
138
|
-
router,
|
|
139
|
-
callback() {
|
|
140
|
-
return router;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
150
|
statics(endpoint, options) {
|
|
145
151
|
const { root, ...props } = options;
|
|
146
152
|
return staticsMiddleware(root, props);
|
|
@@ -163,6 +169,9 @@ export class PlatformExpress {
|
|
|
163
169
|
}
|
|
164
170
|
return parser({ ...options, ...additionalOptions });
|
|
165
171
|
}
|
|
172
|
+
getPlatformApplication() {
|
|
173
|
+
return this.injector.get(PlatformApplication);
|
|
174
|
+
}
|
|
166
175
|
async configureViewsEngine() {
|
|
167
176
|
const injector = this.injector;
|
|
168
177
|
const app = this.injector.get(PlatformApplication);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAGb,mBAAmB,EACnB,eAAe,EAEf,kBAAkB,EAClB,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AAGzD,OAAO,OAAwB,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAwB5E;;;GAGG;AACH,MAAM,OAAO,eAAe;IAiBJ;IAhBb,SAAS,GAAG;QACnB;YACE,OAAO,EAAE,eAAe;YACxB,QAAQ,EAAE,sBAAsB;SACjC;QACD;YACE,OAAO,EAAE,gBAAgB;YACzB,QAAQ,EAAE,uBAAuB;SAClC;QACD;YACE,OAAO,EAAE,eAAe;YACxB,QAAQ,EAAE,sBAAsB;SACjC;KACF,CAAC;IACF,OAAO,CAAgB;I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AC,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 {\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 {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\nimport Express, {RouterOptions} from \"express\";\nimport type multer from \"multer\";\nimport {promisify} from \"util\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformExpressHandler} from \"../services/PlatformExpressHandler\";\nimport {PlatformExpressRequest} from \"../services/PlatformExpressRequest\";\nimport {PlatformExpressResponse} from \"../services/PlatformExpressResponse\";\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 const middlewares = this.injector.settings.get(\"middlewares\", []);\n\n this.injector.settings.set(\n \"middlewares\",\n 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\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.get(\"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"]}
|
|
1
|
+
{"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,aAAa,EACb,UAAU,EAGV,mBAAmB,EACnB,eAAe,EAEf,kBAAkB,EAInB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AACzD,OAAO,EAA0B,mBAAmB,EAAgB,MAAM,uBAAuB,CAAC;AAGlG,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AAwBnE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAIJ;IAHb,SAAS,GAAG,EAAE,CAAC;IACxB,OAAO,CAAgB;IAEvB,YAAsB,QAAyB;QAAzB,aAAQ,GA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C,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 {\n bindContext,\n createContext,\n getContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport {PlatformHandlerMetadata, PlatformHandlerType, PlatformLayer} from \"@tsed/platform-router\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\nimport Express from \"express\";\nimport type multer from \"multer\";\nimport onFinished from \"on-finished\";\nimport {promisify} from \"util\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\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> {\n readonly providers = [];\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>(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>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n onInit() {\n const middlewares = this.injector.settings.get(\"middlewares\", []);\n\n this.injector.settings.set(\n \"middlewares\",\n 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\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 this.useContext();\n }\n\n async afterLoadRoutes() {\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n const platformExceptions = this.injector.get<PlatformExceptions>(PlatformExceptions)!;\n\n // NOT FOUND\n app.use((req: any, res: any, next: any) => {\n const $ctx = getContext()!;\n !$ctx.isDone() && platformExceptions.resourceNotFound($ctx);\n });\n\n // EXCEPTION FILTERS\n app.use((err: any, req: any, res: any, next: any) => {\n const $ctx = getContext()!;\n\n !$ctx.isDone() && platformExceptions.catch(err, $ctx);\n });\n }\n\n mapLayers(layers: PlatformLayer[]) {\n const app = this.getPlatformApplication();\n const rawApp: any = app.getApp();\n\n layers.forEach((layer) => {\n switch (layer.method) {\n case \"statics\":\n rawApp.use(layer.path, this.statics(layer.path as string, layer.opts as any));\n return;\n }\n\n rawApp[layer.method](...layer.getArgs());\n });\n }\n\n mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {\n switch (metadata.type) {\n case PlatformHandlerType.RAW_ERR_FN:\n return (error: unknown, req: any, res: any, next: any) => handler(error, req, res, bindContext(next));\n case PlatformHandlerType.RAW_FN:\n return (req: any, res: any, next: any) => handler(req, res, bindContext(next));\n case PlatformHandlerType.ERR_MIDDLEWARE:\n return async (error: unknown, req: any, res: any, next: any) => {\n const $ctx = getContext<PlatformContext>()!;\n $ctx.next = next;\n $ctx.error = error;\n\n await handler($ctx);\n };\n default:\n return async (req: any, res: any, next: any) => {\n const $ctx = getContext<PlatformContext>()!;\n $ctx.next = next;\n\n await handler($ctx);\n };\n }\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n const invoke = createContext(this.injector);\n\n app.use(async (request: any, response: any, next: any) => {\n const $ctx = await invoke({\n request,\n response\n });\n\n await $ctx.start();\n\n onFinished(response, () => $ctx.finish());\n\n return $ctx.runInContext(next);\n });\n\n return this;\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 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 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 getPlatformApplication() {\n return this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\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
|
@@ -3,15 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export * from "./exports.js";
|
|
5
5
|
export * from "./components/PlatformExpress.js";
|
|
6
|
-
export * from "./decorators/caseSensitive.js";
|
|
7
|
-
export * from "./decorators/mergeParams.js";
|
|
8
|
-
export * from "./decorators/routerSettings.js";
|
|
9
|
-
export * from "./decorators/strict.js";
|
|
10
6
|
export * from "./interfaces/PlatformExpressSettings.js";
|
|
11
7
|
export * from "./interfaces/PlatformExpressStaticsOptions.js";
|
|
12
8
|
export * from "./interfaces/interfaces.js";
|
|
13
9
|
export * from "./middlewares/staticsMiddleware.js";
|
|
14
|
-
export * from "./services/PlatformExpressHandler.js";
|
|
15
|
-
export * from "./services/PlatformExpressRequest.js";
|
|
16
|
-
export * from "./services/PlatformExpressResponse.js";
|
|
17
10
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -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,
|
|
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,sCAAsC,CAAC;AACrD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformExpress\";\nexport * from \"./interfaces/PlatformExpressSettings\";\nexport * from \"./interfaces/PlatformExpressStaticsOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\n"]}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { InjectorService, PlatformAdapter, PlatformBuilder, PlatformContext,
|
|
1
|
+
import { InjectorService, PlatformAdapter, PlatformBuilder, PlatformContext, PlatformMulter, PlatformMulterSettings, PlatformStaticsOptions } from "@tsed/common";
|
|
2
2
|
import { Type } from "@tsed/core";
|
|
3
|
-
import
|
|
3
|
+
import { PlatformHandlerMetadata, PlatformLayer } from "@tsed/platform-router";
|
|
4
|
+
import Express from "express";
|
|
4
5
|
import { PlatformExpressStaticsOptions } from "../interfaces/PlatformExpressStaticsOptions";
|
|
5
|
-
import { PlatformExpressHandler } from "../services/PlatformExpressHandler";
|
|
6
|
-
import { PlatformExpressRequest } from "../services/PlatformExpressRequest";
|
|
7
|
-
import { PlatformExpressResponse } from "../services/PlatformExpressResponse";
|
|
8
6
|
declare module "express" {
|
|
9
7
|
interface Request {
|
|
10
8
|
id: string;
|
|
@@ -13,8 +11,6 @@ declare module "express" {
|
|
|
13
11
|
}
|
|
14
12
|
declare global {
|
|
15
13
|
namespace TsED {
|
|
16
|
-
interface Router extends Express.Router {
|
|
17
|
-
}
|
|
18
14
|
interface Application extends Express.Application {
|
|
19
15
|
}
|
|
20
16
|
interface StaticsOptions extends PlatformExpressStaticsOptions {
|
|
@@ -29,47 +25,36 @@ declare global {
|
|
|
29
25
|
* @platform
|
|
30
26
|
* @express
|
|
31
27
|
*/
|
|
32
|
-
export declare class PlatformExpress implements PlatformAdapter<Express.Application
|
|
28
|
+
export declare class PlatformExpress implements PlatformAdapter<Express.Application> {
|
|
33
29
|
#private;
|
|
34
30
|
protected injector: InjectorService;
|
|
35
|
-
readonly providers:
|
|
36
|
-
provide: typeof PlatformHandler;
|
|
37
|
-
useClass: typeof PlatformExpressHandler;
|
|
38
|
-
} | {
|
|
39
|
-
provide: typeof PlatformResponse;
|
|
40
|
-
useClass: typeof PlatformExpressResponse;
|
|
41
|
-
} | {
|
|
42
|
-
provide: typeof PlatformRequest;
|
|
43
|
-
useClass: typeof PlatformExpressRequest;
|
|
44
|
-
})[];
|
|
31
|
+
readonly providers: never[];
|
|
45
32
|
constructor(injector: InjectorService);
|
|
46
33
|
/**
|
|
47
34
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
48
35
|
* @param module
|
|
49
36
|
* @param settings
|
|
50
37
|
*/
|
|
51
|
-
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Express.Application
|
|
38
|
+
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Express.Application>;
|
|
52
39
|
/**
|
|
53
40
|
* Bootstrap a server application
|
|
54
41
|
* @param module
|
|
55
42
|
* @param settings
|
|
56
43
|
*/
|
|
57
|
-
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Express.Application
|
|
44
|
+
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Express.Application>>;
|
|
58
45
|
onInit(): void;
|
|
59
|
-
useRouter(): this;
|
|
60
46
|
beforeLoadRoutes(): Promise<void>;
|
|
61
47
|
afterLoadRoutes(): Promise<void>;
|
|
48
|
+
mapLayers(layers: PlatformLayer[]): void;
|
|
49
|
+
mapHandler(handler: Function, metadata: PlatformHandlerMetadata): (error: unknown, req: any, res: any, next: any) => any;
|
|
62
50
|
useContext(): this;
|
|
63
|
-
multipart(options: PlatformMulterSettings): PlatformMulter;
|
|
64
51
|
app(): {
|
|
65
52
|
app: any;
|
|
66
53
|
callback(): any;
|
|
67
54
|
};
|
|
68
|
-
|
|
69
|
-
router: import("express-serve-static-core").Router;
|
|
70
|
-
callback(): import("express-serve-static-core").Router;
|
|
71
|
-
};
|
|
55
|
+
multipart(options: PlatformMulterSettings): PlatformMulter;
|
|
72
56
|
statics(endpoint: string, options: PlatformStaticsOptions): (request: any, response: any, next: any) => void;
|
|
73
57
|
bodyParser(type: "json" | "raw" | "text" | "urlencoded", additionalOptions?: any): any;
|
|
58
|
+
private getPlatformApplication;
|
|
74
59
|
private configureViewsEngine;
|
|
75
60
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,14 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export * from "./exports";
|
|
5
5
|
export * from "./components/PlatformExpress";
|
|
6
|
-
export * from "./decorators/caseSensitive";
|
|
7
|
-
export * from "./decorators/mergeParams";
|
|
8
|
-
export * from "./decorators/routerSettings";
|
|
9
|
-
export * from "./decorators/strict";
|
|
10
6
|
export * from "./interfaces/PlatformExpressSettings";
|
|
11
7
|
export * from "./interfaces/PlatformExpressStaticsOptions";
|
|
12
8
|
export * from "./interfaces/interfaces";
|
|
13
9
|
export * from "./middlewares/staticsMiddleware";
|
|
14
|
-
export * from "./services/PlatformExpressHandler";
|
|
15
|
-
export * from "./services/PlatformExpressRequest";
|
|
16
|
-
export * from "./services/PlatformExpressResponse";
|