@tsed/platform-express 7.0.0-beta.12 → 7.0.0-beta.15
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/jest.config.js +14 -0
- package/lib/cjs/components/PlatformExpress.js +72 -66
- 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/cjs/interfaces/PlatformExpressSettings.js.map +1 -1
- package/lib/esm/components/PlatformExpress.js +72 -67
- 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/esm/interfaces/PlatformExpressSettings.js.map +1 -1
- package/lib/types/components/PlatformExpress.d.ts +11 -26
- package/lib/types/index.d.ts +0 -7
- package/lib/types/interfaces/PlatformExpressSettings.d.ts +4 -4
- package/package.json +27 -20
- 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
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
+
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require("@tsed/jest-config")(__dirname, "platform-express"),
|
|
6
|
+
coverageThreshold: {
|
|
7
|
+
global: {
|
|
8
|
+
statements: 100,
|
|
9
|
+
branches: 78.94,
|
|
10
|
+
functions: 100,
|
|
11
|
+
lines: 100
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -1,39 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _PlatformExpress_multer;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.PlatformExpress = void 0;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
6
|
-
const express_1 = tslib_1.__importDefault(require("express"));
|
|
7
5
|
const common_1 = require("@tsed/common");
|
|
8
|
-
const util_1 = require("util");
|
|
9
6
|
const core_1 = require("@tsed/core");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
7
|
+
const platform_router_1 = require("@tsed/platform-router");
|
|
8
|
+
const express_1 = tslib_1.__importDefault(require("express"));
|
|
9
|
+
const on_finished_1 = tslib_1.__importDefault(require("on-finished"));
|
|
10
|
+
const util_1 = require("util");
|
|
13
11
|
const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
|
|
14
12
|
/**
|
|
15
13
|
* @platform
|
|
16
14
|
* @express
|
|
17
15
|
*/
|
|
18
16
|
class PlatformExpress {
|
|
17
|
+
injector;
|
|
18
|
+
providers = [];
|
|
19
|
+
#multer;
|
|
19
20
|
constructor(injector) {
|
|
20
21
|
this.injector = injector;
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
provide: common_1.PlatformHandler,
|
|
24
|
-
useClass: PlatformExpressHandler_1.PlatformExpressHandler
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
provide: common_1.PlatformResponse,
|
|
28
|
-
useClass: PlatformExpressResponse_1.PlatformExpressResponse
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
provide: common_1.PlatformRequest,
|
|
32
|
-
useClass: PlatformExpressRequest_1.PlatformExpressRequest
|
|
33
|
-
}
|
|
34
|
-
];
|
|
35
|
-
_PlatformExpress_multer.set(this, void 0);
|
|
36
|
-
Promise.resolve().then(() => tslib_1.__importStar(require("multer"))).then(({ default: multer }) => (tslib_1.__classPrivateFieldSet(this, _PlatformExpress_multer, multer, "f")));
|
|
22
|
+
Promise.resolve().then(() => tslib_1.__importStar(require("multer"))).then(({ default: multer }) => (this.#multer = multer));
|
|
37
23
|
}
|
|
38
24
|
/**
|
|
39
25
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
@@ -58,21 +44,15 @@ class PlatformExpress {
|
|
|
58
44
|
});
|
|
59
45
|
}
|
|
60
46
|
onInit() {
|
|
61
|
-
|
|
47
|
+
const middlewares = this.injector.settings.get("middlewares", []);
|
|
48
|
+
this.injector.settings.set("middlewares", middlewares.filter((middleware) => {
|
|
62
49
|
const name = (0, core_1.nameOf)(middleware);
|
|
63
50
|
if (["textParser", "jsonParser", "rawParser", "urlencodedParser"].includes(name)) {
|
|
64
51
|
this.injector.settings.set(`express.bodyParser.${name.replace("Parser", "")}`, () => middleware);
|
|
65
52
|
return false;
|
|
66
53
|
}
|
|
67
54
|
return true;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
useRouter() {
|
|
71
|
-
const { logger } = this.injector;
|
|
72
|
-
const app = this.injector.get(common_1.PlatformApplication);
|
|
73
|
-
logger.debug("Mount app router");
|
|
74
|
-
app.getApp().use(app.getRouter());
|
|
75
|
-
return this;
|
|
55
|
+
}));
|
|
76
56
|
}
|
|
77
57
|
async beforeLoadRoutes() {
|
|
78
58
|
const injector = this.injector;
|
|
@@ -80,34 +60,80 @@ class PlatformExpress {
|
|
|
80
60
|
// disable x-powered-by header
|
|
81
61
|
injector.settings.get("env") === core_1.Env.PROD && app.getApp().disable("x-powered-by");
|
|
82
62
|
await this.configureViewsEngine();
|
|
63
|
+
this.useContext();
|
|
83
64
|
}
|
|
84
65
|
async afterLoadRoutes() {
|
|
85
|
-
const injector = this.injector;
|
|
86
66
|
const app = this.injector.get(common_1.PlatformApplication);
|
|
67
|
+
const platformExceptions = this.injector.get(common_1.PlatformExceptions);
|
|
87
68
|
// NOT FOUND
|
|
88
69
|
app.use((req, res, next) => {
|
|
89
|
-
|
|
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
|
-
|
|
95
|
-
|
|
75
|
+
const $ctx = (0, common_1.getContext)();
|
|
76
|
+
!$ctx.isDone() && platformExceptions.catch(err, $ctx);
|
|
96
77
|
});
|
|
97
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
|
+
}
|
|
98
112
|
useContext() {
|
|
99
|
-
const
|
|
100
|
-
logger.debug("Mount app context");
|
|
113
|
+
const app = this.getPlatformApplication();
|
|
101
114
|
const invoke = (0, common_1.createContext)(this.injector);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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);
|
|
106
123
|
});
|
|
107
124
|
return this;
|
|
108
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
|
+
}
|
|
109
135
|
multipart(options) {
|
|
110
|
-
const m =
|
|
136
|
+
const m = this.#multer(options);
|
|
111
137
|
const makePromise = (multer, name) => {
|
|
112
138
|
// istanbul ignore next
|
|
113
139
|
if (!multer[name])
|
|
@@ -125,28 +151,6 @@ class PlatformExpress {
|
|
|
125
151
|
makePromise(m, "single");
|
|
126
152
|
return m;
|
|
127
153
|
}
|
|
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
154
|
statics(endpoint, options) {
|
|
151
155
|
const { root, ...props } = options;
|
|
152
156
|
return (0, staticsMiddleware_1.staticsMiddleware)(root, props);
|
|
@@ -169,6 +173,9 @@ class PlatformExpress {
|
|
|
169
173
|
}
|
|
170
174
|
return parser({ ...options, ...additionalOptions });
|
|
171
175
|
}
|
|
176
|
+
getPlatformApplication() {
|
|
177
|
+
return this.injector.get(common_1.PlatformApplication);
|
|
178
|
+
}
|
|
172
179
|
async configureViewsEngine() {
|
|
173
180
|
const injector = this.injector;
|
|
174
181
|
const app = this.injector.get(common_1.PlatformApplication);
|
|
@@ -196,5 +203,4 @@ class PlatformExpress {
|
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
205
|
exports.PlatformExpress = PlatformExpress;
|
|
199
|
-
_PlatformExpress_multer = new WeakMap();
|
|
200
206
|
//# sourceMappingURL=PlatformExpress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;;AACA,8DAA+C;AAE/C,yCAcsB;AACtB,+BAA+B;AAC/B,qCAAyD;AACzD,+EAA0E;AAC1E,iFAA4E;AAC5E,+EAA0E;AAC1E,wEAAmE;AA0BnE;;;GAGG;AACH,MAAa,eAAe;IAiB1B,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAhBtC,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,+CAAsB;aACjC;YACD;gBACE,OAAO,EAAE,yBAAgB;gBACzB,QAAQ,EAAE,iDAAuB;aAClC;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,+CAAsB;aACjC;SACF,CAAC;QACF,0CAAuB;QAGrB,0DAAO,QAAQ,IAAE,IAAI,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,+BAAA,IAAI,2BAAW,MAAM,MAAA,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAiB,EAAE,WAAwC,EAAE;QACzE,OAAO,wBAAe,CAAC,MAAM,CAAsC,MAAM,EAAE;YACzE,GAAG,QAAQ;YACX,OAAO,EAAE,eAAe;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,SAA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AC;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"]}
|
|
1
|
+
{"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;AAAA,yCAasB;AACtB,qCAAyD;AACzD,2DAAkG;AAGlG,8DAA8B;AAE9B,sEAAqC;AACrC,+BAA+B;AAE/B,wEAAmE;AAwBnE;;;GAGG;AACH,MAAa,eAAe;IAIJ;IAHb,SAAS,GAAG,EAAE,CAAC;IACxB,OAAO,CAAgB;IAEvB,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAC7C,0DAAO,QAAQ,IAAE,IAAI,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAiB,EAAE,WAAwC,EAAE;QACzE,OAAO,wBAAe,CAAC,MAAM,CAAsB,MAAM,EAAE;YACzD,GAAG,QAAQ;YACX,OAAO,EAAE,eAAe;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAiB,EAAE,WAAwC,EAAE;QAClF,OAAO,wBAAe,CAAC,SAAS,CAAsB,MAAM,EAAE;YAC5D,GAAG,QAAQ;YACX,OAAO,EAAE,eAAe;SACzB,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CACxB,aAAa,EACb,WAAW,CAAC,MAAM,C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AAsB,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;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {RouterOptions} from \"express\";\nimport type {OptionsJson, OptionsText, Options, OptionsUrlencoded} from \"body-parser\";\nimport type {NextHandleFunction} from \"connect\";\n\nexport interface PlatformExpressSettings {\n /**\n * Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).\n */\n router?: RouterOptions;\n /**\n * Express application\n */\n app?: Express.Application;\n\n /**\n * body parser configuration\n */\n bodyParser?: {\n json?: (opts?: OptionsJson) => NextHandleFunction | OptionsJson;\n text?: (opts?: OptionsText) => NextHandleFunction | OptionsText;\n raw?: (opts?: Options) => NextHandleFunction | Options;\n urlencoded?: (opts?: OptionsUrlencoded) => NextHandleFunction | OptionsUrlencoded;\n };\n}\n"]}
|
|
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,36 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { bindContext, createContext, getContext, PlatformApplication, PlatformBuilder, PlatformExceptions } from "@tsed/common";
|
|
2
|
+
import { Env, isFunction, nameOf } from "@tsed/core";
|
|
3
|
+
import { PlatformHandlerType } from "@tsed/platform-router";
|
|
3
4
|
import Express from "express";
|
|
4
|
-
import
|
|
5
|
+
import onFinished from "on-finished";
|
|
5
6
|
import { promisify } from "util";
|
|
6
|
-
import { Env, isFunction, nameOf } from "@tsed/core";
|
|
7
|
-
import { PlatformExpressHandler } from "../services/PlatformExpressHandler.js";
|
|
8
|
-
import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
|
|
9
|
-
import { PlatformExpressRequest } from "../services/PlatformExpressRequest.js";
|
|
10
7
|
import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
|
|
11
8
|
/**
|
|
12
9
|
* @platform
|
|
13
10
|
* @express
|
|
14
11
|
*/
|
|
15
12
|
export class PlatformExpress {
|
|
13
|
+
injector;
|
|
14
|
+
providers = [];
|
|
15
|
+
#multer;
|
|
16
16
|
constructor(injector) {
|
|
17
17
|
this.injector = injector;
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
provide: PlatformHandler,
|
|
21
|
-
useClass: PlatformExpressHandler
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
provide: PlatformResponse,
|
|
25
|
-
useClass: PlatformExpressResponse
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
provide: PlatformRequest,
|
|
29
|
-
useClass: PlatformExpressRequest
|
|
30
|
-
}
|
|
31
|
-
];
|
|
32
|
-
_PlatformExpress_multer.set(this, void 0);
|
|
33
|
-
import("multer").then(({ default: multer }) => (__classPrivateFieldSet(this, _PlatformExpress_multer, multer, "f")));
|
|
18
|
+
import("multer").then(({ default: multer }) => (this.#multer = multer));
|
|
34
19
|
}
|
|
35
20
|
/**
|
|
36
21
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
@@ -55,21 +40,15 @@ export class PlatformExpress {
|
|
|
55
40
|
});
|
|
56
41
|
}
|
|
57
42
|
onInit() {
|
|
58
|
-
|
|
43
|
+
const middlewares = this.injector.settings.get("middlewares", []);
|
|
44
|
+
this.injector.settings.set("middlewares", middlewares.filter((middleware) => {
|
|
59
45
|
const name = nameOf(middleware);
|
|
60
46
|
if (["textParser", "jsonParser", "rawParser", "urlencodedParser"].includes(name)) {
|
|
61
47
|
this.injector.settings.set(`express.bodyParser.${name.replace("Parser", "")}`, () => middleware);
|
|
62
48
|
return false;
|
|
63
49
|
}
|
|
64
50
|
return true;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
useRouter() {
|
|
68
|
-
const { logger } = this.injector;
|
|
69
|
-
const app = this.injector.get(PlatformApplication);
|
|
70
|
-
logger.debug("Mount app router");
|
|
71
|
-
app.getApp().use(app.getRouter());
|
|
72
|
-
return this;
|
|
51
|
+
}));
|
|
73
52
|
}
|
|
74
53
|
async beforeLoadRoutes() {
|
|
75
54
|
const injector = this.injector;
|
|
@@ -77,34 +56,80 @@ export class PlatformExpress {
|
|
|
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
|
-
|
|
87
|
-
|
|
66
|
+
const $ctx = getContext();
|
|
67
|
+
!$ctx.isDone() && platformExceptions.resourceNotFound($ctx);
|
|
88
68
|
});
|
|
89
69
|
// EXCEPTION FILTERS
|
|
90
70
|
app.use((err, req, res, next) => {
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
const $ctx = getContext();
|
|
72
|
+
!$ctx.isDone() && platformExceptions.catch(err, $ctx);
|
|
73
|
+
});
|
|
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());
|
|
93
85
|
});
|
|
94
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
|
+
}
|
|
95
108
|
useContext() {
|
|
96
|
-
const
|
|
97
|
-
logger.debug("Mount app context");
|
|
109
|
+
const app = this.getPlatformApplication();
|
|
98
110
|
const invoke = createContext(this.injector);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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);
|
|
103
119
|
});
|
|
104
120
|
return this;
|
|
105
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
|
+
}
|
|
106
131
|
multipart(options) {
|
|
107
|
-
const m =
|
|
132
|
+
const m = this.#multer(options);
|
|
108
133
|
const makePromise = (multer, name) => {
|
|
109
134
|
// istanbul ignore next
|
|
110
135
|
if (!multer[name])
|
|
@@ -122,28 +147,6 @@ export class PlatformExpress {
|
|
|
122
147
|
makePromise(m, "single");
|
|
123
148
|
return m;
|
|
124
149
|
}
|
|
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
150
|
statics(endpoint, options) {
|
|
148
151
|
const { root, ...props } = options;
|
|
149
152
|
return staticsMiddleware(root, props);
|
|
@@ -166,6 +169,9 @@ export class PlatformExpress {
|
|
|
166
169
|
}
|
|
167
170
|
return parser({ ...options, ...additionalOptions });
|
|
168
171
|
}
|
|
172
|
+
getPlatformApplication() {
|
|
173
|
+
return this.injector.get(PlatformApplication);
|
|
174
|
+
}
|
|
169
175
|
async configureViewsEngine() {
|
|
170
176
|
const injector = this.injector;
|
|
171
177
|
const app = this.injector.get(PlatformApplication);
|
|
@@ -192,5 +198,4 @@ export class PlatformExpress {
|
|
|
192
198
|
}
|
|
193
199
|
}
|
|
194
200
|
}
|
|
195
|
-
_PlatformExpress_multer = new WeakMap();
|
|
196
201
|
//# sourceMappingURL=PlatformExpress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;AACA,OAAO,OAAwB,MAAM,SAAS,CAAC;AAE/C,OAAO,EACL,aAAa,EAGb,mBAAmB,EACnB,eAAe,EAEf,kBAAkB,EAClB,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AACzD,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AA0BnE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAiB1B,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAhBtC,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,sBAAsB;aACjC;YACD;gBACE,OAAO,EAAE,gBAAgB;gBACzB,QAAQ,EAAE,uBAAuB;aAClC;YACD;gBACE,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,sBAAsB;aACjC;SACF,CAAC;QACF,0CAAuB;QAGrB,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,uBAAA,IAAI,2BAAW,MAAM,MAAA,CAAC,CAAC,CAAC;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AAC,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"]}
|
|
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,GAAR,QAAQ,CAAiB;QAC7C,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAiB,EAAE,WAAwC,EAAE;QACzE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apter,\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"]}
|