@tsed/platform-express 6.116.3 → 6.116.6
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 +6 -6
- package/lib/cjs/components/PlatformExpress.js.map +1 -1
- package/lib/esm/components/PlatformExpress.js +6 -6
- package/lib/esm/components/PlatformExpress.js.map +1 -1
- package/lib/types/components/PlatformExpress.d.ts +3 -3
- package/package.json +14 -14
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlatformExpress = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const express_1 = tslib_1.__importDefault(require("express"));
|
|
6
5
|
const common_1 = require("@tsed/common");
|
|
7
|
-
const util_1 = require("util");
|
|
8
6
|
const core_1 = require("@tsed/core");
|
|
7
|
+
const express_1 = tslib_1.__importDefault(require("express"));
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
|
|
9
10
|
const PlatformExpressHandler_1 = require("../services/PlatformExpressHandler");
|
|
10
|
-
const PlatformExpressResponse_1 = require("../services/PlatformExpressResponse");
|
|
11
11
|
const PlatformExpressRequest_1 = require("../services/PlatformExpressRequest");
|
|
12
|
-
const
|
|
12
|
+
const PlatformExpressResponse_1 = require("../services/PlatformExpressResponse");
|
|
13
13
|
/**
|
|
14
14
|
* @platform
|
|
15
15
|
* @express
|
|
@@ -100,8 +100,8 @@ class PlatformExpress {
|
|
|
100
100
|
const invoke = (0, common_1.createContext)(this.injector);
|
|
101
101
|
const app = this.injector.get(common_1.PlatformApplication);
|
|
102
102
|
app.getApp().use(async (request, response, next) => {
|
|
103
|
-
|
|
104
|
-
return
|
|
103
|
+
await invoke({ request, response });
|
|
104
|
+
return next();
|
|
105
105
|
});
|
|
106
106
|
return this;
|
|
107
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{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BAAmB,CAAE,CAAC;QAE9F,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 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 runInContext\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 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 const $ctx = await invoke({request, response});\n\n return $ctx.runInContext(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":"","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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,11 +1,11 @@
|
|
|
1
|
-
import Express from "express";
|
|
2
1
|
import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
|
|
3
|
-
import { promisify } from "util";
|
|
4
2
|
import { Env, isFunction, nameOf } from "@tsed/core";
|
|
3
|
+
import Express from "express";
|
|
4
|
+
import { promisify } from "util";
|
|
5
|
+
import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
|
|
5
6
|
import { PlatformExpressHandler } from "../services/PlatformExpressHandler.js";
|
|
6
|
-
import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
|
|
7
7
|
import { PlatformExpressRequest } from "../services/PlatformExpressRequest.js";
|
|
8
|
-
import {
|
|
8
|
+
import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
|
|
9
9
|
/**
|
|
10
10
|
* @platform
|
|
11
11
|
* @express
|
|
@@ -96,8 +96,8 @@ export class PlatformExpress {
|
|
|
96
96
|
const invoke = createContext(this.injector);
|
|
97
97
|
const app = this.injector.get(PlatformApplication);
|
|
98
98
|
app.getApp().use(async (request, response, next) => {
|
|
99
|
-
|
|
100
|
-
return
|
|
99
|
+
await invoke({ request, response });
|
|
100
|
+
return next();
|
|
101
101
|
});
|
|
102
102
|
return this;
|
|
103
103
|
}
|
|
@@ -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,EAGjB,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;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AAM,IAAI,CAAC,QAAQ,EAAE;gBACvB,MAAM,EAAC,aAAa,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;gBAC7D,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAgB,aAAa,CAAE,CAAC;gBAClE,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;gBAE7B,aAAa,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,EAAE;oBACzD,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3C,CAAC,CAAC,CAAC;gBAEH,aAAa,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;gBACjF,aAAa,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;aAChE;SACF;QAAC,OAAO,KAAK,EAAE;YACd,uBAAuB;YACvB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;CACF","sourcesContent":["import type multer from \"multer\";\nimport Express, {RouterOptions} from \"express\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions,\n runInContext\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 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 const $ctx = await invoke({request, response});\n\n return $ctx.runInContext(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,aAAa,EAGb,mBAAmB,EACnB,eAAe,EAEf,kBAAkB,EAClB,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,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,IAAI,CAAC,QAAQ,CAAC;QAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAA2C,mBAAmB,CAAE,CAAC;QAE9F,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,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;gBAC7D,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAgB,aAAa,CAAE,CAAC;gBAClE,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;gBAE7B,aAAa,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,EAAE;oBACzD,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3C,CAAC,CAAC,CAAC;gBAEH,aAAa,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;gBACjF,aAAa,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;aAChE;SACF;QAAC,OAAO,KAAK,EAAE;YACd,uBAAuB;YACvB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;CACF","sourcesContent":["import {\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,10 +1,10 @@
|
|
|
1
|
-
import Express, { RouterOptions } from "express";
|
|
2
1
|
import { InjectorService, PlatformAdapter, PlatformBuilder, PlatformContext, PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRequest, PlatformResponse, PlatformStaticsOptions } from "@tsed/common";
|
|
3
2
|
import { Type } from "@tsed/core";
|
|
3
|
+
import Express, { RouterOptions } from "express";
|
|
4
|
+
import { PlatformExpressStaticsOptions } from "../interfaces/PlatformExpressStaticsOptions";
|
|
4
5
|
import { PlatformExpressHandler } from "../services/PlatformExpressHandler";
|
|
5
|
-
import { PlatformExpressResponse } from "../services/PlatformExpressResponse";
|
|
6
6
|
import { PlatformExpressRequest } from "../services/PlatformExpressRequest";
|
|
7
|
-
import {
|
|
7
|
+
import { PlatformExpressResponse } from "../services/PlatformExpressResponse";
|
|
8
8
|
declare module "express" {
|
|
9
9
|
interface Request {
|
|
10
10
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-express",
|
|
3
|
-
"version": "6.116.
|
|
3
|
+
"version": "6.116.6",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"tslib": "2.4.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@tsed/common": "6.116.
|
|
61
|
-
"@tsed/core": "6.116.
|
|
62
|
-
"@tsed/di": "6.116.
|
|
63
|
-
"@tsed/platform-test-utils": "6.116.
|
|
64
|
-
"@tsed/platform-views": "6.116.
|
|
60
|
+
"@tsed/common": "6.116.6",
|
|
61
|
+
"@tsed/core": "6.116.6",
|
|
62
|
+
"@tsed/di": "6.116.6",
|
|
63
|
+
"@tsed/platform-test-utils": "6.116.6",
|
|
64
|
+
"@tsed/platform-views": "6.116.6",
|
|
65
65
|
"@types/body-parser": "1.19.2",
|
|
66
66
|
"@types/compression": "1.7.2",
|
|
67
67
|
"@types/cookie-parser": "1.4.2",
|
|
@@ -77,14 +77,14 @@
|
|
|
77
77
|
"method-override": "3.0.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@tsed/common": "^6.116.
|
|
81
|
-
"@tsed/core": "^6.116.
|
|
82
|
-
"@tsed/di": "^6.116.
|
|
83
|
-
"@tsed/json-mapper": "^6.116.
|
|
84
|
-
"@tsed/logger": ">=6.
|
|
85
|
-
"@tsed/openspec": "^6.116.
|
|
86
|
-
"@tsed/platform-views": "^6.116.
|
|
87
|
-
"@tsed/schema": "^6.116.
|
|
80
|
+
"@tsed/common": "^6.116.6",
|
|
81
|
+
"@tsed/core": "^6.116.6",
|
|
82
|
+
"@tsed/di": "^6.116.6",
|
|
83
|
+
"@tsed/json-mapper": "^6.116.6",
|
|
84
|
+
"@tsed/logger": ">=6.2.0",
|
|
85
|
+
"@tsed/openspec": "^6.116.6",
|
|
86
|
+
"@tsed/platform-views": "^6.116.6",
|
|
87
|
+
"@tsed/schema": "^6.116.6",
|
|
88
88
|
"@types/multer": "^1.4.5",
|
|
89
89
|
"body-parser": "^1.19.0",
|
|
90
90
|
"multer": "^1.4.5-lts.1"
|