@tsed/common 6.128.1 → 6.128.2
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/coverage.json +3 -3
- package/lib/cjs/builder/PlatformBuilder.js +1 -4
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/services/PlatformAdapter.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +2 -5
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/services/PlatformAdapter.js.map +1 -1
- package/lib/types/services/PlatformAdapter.d.ts +3 -1
- package/package.json +15 -15
package/coverage.json
CHANGED
|
@@ -141,10 +141,7 @@ class PlatformBuilder {
|
|
|
141
141
|
if (req && res) {
|
|
142
142
|
return this.callback()(req, res);
|
|
143
143
|
}
|
|
144
|
-
|
|
145
|
-
return (req, res) => {
|
|
146
|
-
(0, di_1.runInContext)(undefined, () => cb(req, res), this.injector);
|
|
147
|
-
};
|
|
144
|
+
return this.app.callback();
|
|
148
145
|
}
|
|
149
146
|
log(...data) {
|
|
150
147
|
return !this.disableBootstrapLog && this.logger.info(...data, this.diff());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAwC;AACxC,iCAAoH;AACpH,qEAAiE;AAKjE,4FAAuF;AACvF,mDAA8C;AAC9C,iEAAqF;AACrF,yEAAoE;AACpE,gEAA2D;AAC3D,kEAA6D;AAC7D,4DAAuD;AACvD,gEAA2D;AAC3D,kEAA6D;AAC7D,sDAAiD;AAEjD;;GAEG;AACH,MAAa,eAAe;IACnB,MAAM,CAAC,OAAO,CAAkC;IAE9C,IAAI,GAAW,EAAE,CAAC;IACjB,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;IACtB,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A,qCAAiB,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAC5H,OAAO,CACC,CAAC;IACb,CAAC;IAES,KAAK,CAAC,aAAa;QAC3B,IAAI,CAAC,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC;IAES,KAAK,CAAC,SAAS;QACvB,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC;QAEhC,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAE9B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAClF,MAAM,CAAC,IAAI,CAAC,IAAA,yBAAW,EAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9F;IACH,CAAC;CACF;AAzVD,0CAyVC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, runInContext, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport type Https from \"https\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {Route} from \"../interfaces/Route\";\nimport {GlobalAcceptMimesMiddleware} from \"../middlewares/GlobalAcceptMimesMiddleware\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {printRoutes} from \"../utils/printRoutes\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {\n public static adapter: Type<PlatformAdapter<any, any>>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n readonly #injector: InjectorService;\n readonly #rootModule: Type<any>;\n readonly #adapter: PlatformAdapter<App, Router>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n\n const configuration = getConfiguration(settings, module);\n const adapterKlass: Type<PlatformAdapter<App, Router>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n configuration.PLATFORM_NAME = name;\n this.name = name;\n\n this.#injector = createInjector({\n adapter: adapterKlass,\n settings: configuration\n });\n\n this.#adapter = this.#injector.get<PlatformAdapter<App, Router>>(PlatformAdapter)!;\n\n this.createHttpServers();\n\n this.#adapter.onInit && this.#adapter.onInit();\n\n this.log(\"Injector created...\");\n }\n\n get injector(): InjectorService {\n return this.#injector;\n }\n\n get rootModule(): any {\n return this.#injector.get(this.#rootModule);\n }\n\n get app(): PlatformApplication<App, Router> {\n return this.injector.get<PlatformApplication<App, Router>>(PlatformApplication)!;\n }\n\n get platform() {\n return this.injector.get<Platform>(Platform)!;\n }\n\n get adapter() {\n return this.#adapter;\n }\n\n /**\n * Return the settings configured by the decorator @@Configuration@@.\n *\n * ```typescript\n * @Configuration({\n * rootDir: Path.resolve(__dirname),\n * port: 8000,\n * httpsPort: 8080,\n * mount: {\n * \"/rest\": \"${rootDir}/controllers/**\\/*.js\"\n * }\n * })\n * export class Server {\n * $onInit(){\n * console.log(this.settings); // {rootDir, port, httpsPort,...}\n * }\n * }\n * ```\n *\n * @returns {PlatformConfiguration}\n */\n get settings() {\n return this.injector.settings;\n }\n\n get logger() {\n return this.injector.logger;\n }\n\n get disableBootstrapLog() {\n return this.settings.get(\"logger.disableBootstrapLog\");\n }\n\n static create<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings,\n disableComponentsScan: true\n });\n }\n\n static build<App = TsED.Application, Router = TsED.Router>(\n module: Type<any>,\n {adapter, ...settings}: PlatformBuilderSettings<App, Router>\n ) {\n return new PlatformBuilder(adapter, module, settings);\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n const configuration = getConfiguration(settings, module);\n const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;\n\n if (!disableComponentsScan) {\n const {importProviders} = await import(\"@tsed/components-scan\");\n await importProviders(configuration);\n }\n\n return this.build<App, Router>(module, configuration).bootstrap();\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => void;\n callback(req: IncomingMessage, res: ServerResponse): void;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.callback()(req, res);\n }\n\n const cb = this.app.callback();\n\n return (req: IncomingMessage, res: ServerResponse) => {\n runInContext(undefined, () => cb(req, res), this.injector);\n };\n }\n\n log(...data: any[]) {\n return !this.disableBootstrapLog && this.logger.info(...data, this.diff());\n }\n\n /**\n * Add classes to the components list\n * @param classes\n * @deprecated\n */\n public addComponents(classes: any | any[]) {\n this.settings.set(\"componentsScan\", this.settings.get(\"componentsScan\", []).concat(classes));\n\n return this;\n }\n\n /**\n * Add classes decorated by @@Controller@@ to components container.\n *\n * ### Example\n *\n * ```typescript\n * @Controller('/ctrl')\n * class MyController{\n * }\n *\n * platform.addControllers('/rest', [MyController])\n * ```\n *\n * ::: tip\n * If the MyController class isn't decorated, the class will be ignored.\n * :::\n *\n * @param {string} endpoint\n * @param {any[]} controllers\n */\n public addControllers(endpoint: string, controllers: TokenProvider | TokenProvider[]) {\n [].concat(controllers).forEach((token) => {\n this.settings.routes.push({token, route: endpoint});\n });\n }\n\n public async runLifecycle() {\n setLoggerConfiguration(this.injector);\n\n await this.loadInjector();\n\n this.#adapter.useContext && this.#adapter.useContext();\n this.#adapter.useRouter && this.#adapter.useRouter();\n\n await this.loadRoutes();\n await this.logRoutes();\n\n return this;\n }\n\n async loadInjector() {\n const {injector} = this;\n this.log(\"Build providers\");\n\n await injector.loadModule(this.#rootModule);\n\n this.log(\"Settings and injector loaded...\");\n\n await this.callHook(\"$afterInit\");\n }\n\n async listen(network = true) {\n if (!this.#promise) {\n await this.bootstrap();\n }\n\n await this.callHook(\"$beforeListen\");\n\n if (network) {\n await this.listenServers();\n }\n\n await this.callHook(\"$afterListen\");\n\n await this.ready();\n }\n\n async stop() {\n await this.callHook(\"$onDestroy\");\n await this.injector.destroy();\n\n this.#listeners.map((server) => {\n return new Promise((resolve) => server.close(() => resolve(undefined)));\n });\n }\n\n public async ready() {\n const {startedAt} = this;\n\n await this.callHook(\"$onReady\");\n await this.injector.emit(\"$onServerReady\");\n\n this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);\n }\n\n async callHook(hook: string, ...args: any[]) {\n const {injector} = this;\n\n if (!this.disableBootstrapLog) {\n injector.logger.debug(`\\x1B[1mCall hook ${hook}\\x1B[22m`);\n }\n\n // Load middlewares for the given hook\n this.loadMiddlewaresFor(hook);\n\n // call hooks added by providers\n await injector.emit(hook, ...args);\n }\n\n async loadStatics(hook: string): Promise<void> {\n const statics = this.settings.get<PlatformStaticsSettings>(\"statics\");\n\n getStaticsOptions(statics).forEach(({path, options}) => {\n if (options.hook === hook) {\n this.platform.app.statics(path, options);\n }\n });\n }\n\n useProvider(token: Type<any>, settings?: Partial<ProviderOpts>) {\n this.injector.addProvider(token, settings);\n\n return this;\n }\n\n async bootstrap() {\n this.#promise = this.#promise || this.runLifecycle();\n\n return this.#promise;\n }\n\n protected async loadRoutes() {\n this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());\n\n // istanbul ignore next\n if (this.settings.get(\"logger.level\") !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\n }\n\n if (this.settings.get(\"acceptMimes\", []).length) {\n this.app.use(GlobalAcceptMimesMiddleware);\n }\n\n this.log(\"Load routes\");\n\n if (this.rootModule.$beforeRoutesInit) {\n await this.rootModule.$beforeRoutesInit();\n this.rootModule.$beforeRoutesInit = () => {};\n }\n\n await this.loadStatics(\"$beforeRoutesInit\");\n await this.callHook(\"$beforeRoutesInit\");\n\n const routes = this.injector.settings.get<Route[]>(\"routes\");\n\n this.platform.addRoutes(routes);\n\n await this.callHook(\"$onRoutesInit\");\n\n await this.loadStatics(\"$afterRoutesInit\");\n\n await this.callHook(\"$afterRoutesInit\");\n\n this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());\n }\n\n protected diff() {\n const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);\n this.current = new Date();\n return ms;\n }\n\n /**\n * Load middlewares from configuration for the given hook\n * @param hook\n * @protected\n */\n protected loadMiddlewaresFor(hook: string): void {\n return getMiddlewaresForHook(hook, this.settings, \"$beforeRoutesInit\").forEach(({use}) => {\n this.app.use(use);\n });\n }\n\n protected createHttpServers() {\n this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(\n Boolean\n ) as any[];\n }\n\n protected async listenServers(): Promise<void> {\n this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));\n }\n\n protected async logRoutes() {\n const {logger, platform} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.get(\"logger.disableRoutesSummary\") && !this.disableBootstrapLog) {\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", platform.getRoutes())));\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAwC;AACxC,iCAAoH;AACpH,qEAAiE;AAKjE,4FAAuF;AACvF,mDAA8C;AAC9C,iEAAqF;AACrF,yEAAoE;AACpE,gEAA2D;AAC3D,kEAA6D;AAC7D,4DAAuD;AACvD,gEAA2D;AAC3D,kEAA6D;AAC7D,sDAAiD;AAEjD;;GAEG;AACH,MAAa,eAAe;IACnB,MAAM,CAAC,OAAO,CAAkC;IAE9C,IAAI,GAAW,EAAE,CAAC;IACjB,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;IACtB,SAAS,CAAkB;IAC3B,WAAW,CAAY;IACvB,QAAQ,CAA+B;IAChD,QAAQ,CAAgB;IACxB,QAAQ,CAA2C;IACnD,UAAU,GAA8B,EAAE,CAAC;IAE3C,YAAsB,OAAuD,EAAE,MAAY,EAAE,QAAqC;QAChI,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAE1B,MAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzD,MAAM,YAAY,GAAuC,OAAO,IAAK,eAAe,CAAC,OAAe,CAAC;QACrG,MAAM,IAAI,GAAG,IAAA,aAAM,EAAC,YAAY,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAExE,aAAa,CAAC,aAAa,GAAG,IAAI,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,IAAI,CAAC,SAAS,GAAG,IAAA,+BAAc,EAAC;YAC9B,OAAO,EAA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, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport type Https from \"https\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {Route} from \"../interfaces/Route\";\nimport {GlobalAcceptMimesMiddleware} from \"../middlewares/GlobalAcceptMimesMiddleware\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {printRoutes} from \"../utils/printRoutes\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {\n public static adapter: Type<PlatformAdapter<any, any>>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n readonly #injector: InjectorService;\n readonly #rootModule: Type<any>;\n readonly #adapter: PlatformAdapter<App, Router>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n\n const configuration = getConfiguration(settings, module);\n const adapterKlass: Type<PlatformAdapter<App, Router>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n configuration.PLATFORM_NAME = name;\n this.name = name;\n\n this.#injector = createInjector({\n adapter: adapterKlass,\n settings: configuration\n });\n\n this.#adapter = this.#injector.get<PlatformAdapter<App, Router>>(PlatformAdapter)!;\n\n this.createHttpServers();\n\n this.#adapter.onInit && this.#adapter.onInit();\n\n this.log(\"Injector created...\");\n }\n\n get injector(): InjectorService {\n return this.#injector;\n }\n\n get rootModule(): any {\n return this.#injector.get(this.#rootModule);\n }\n\n get app(): PlatformApplication<App, Router> {\n return this.injector.get<PlatformApplication<App, Router>>(PlatformApplication)!;\n }\n\n get platform() {\n return this.injector.get<Platform>(Platform)!;\n }\n\n get adapter() {\n return this.#adapter;\n }\n\n /**\n * Return the settings configured by the decorator @@Configuration@@.\n *\n * ```typescript\n * @Configuration({\n * rootDir: Path.resolve(__dirname),\n * port: 8000,\n * httpsPort: 8080,\n * mount: {\n * \"/rest\": \"${rootDir}/controllers/**\\/*.js\"\n * }\n * })\n * export class Server {\n * $onInit(){\n * console.log(this.settings); // {rootDir, port, httpsPort,...}\n * }\n * }\n * ```\n *\n * @returns {PlatformConfiguration}\n */\n get settings() {\n return this.injector.settings;\n }\n\n get logger() {\n return this.injector.logger;\n }\n\n get disableBootstrapLog() {\n return this.settings.get(\"logger.disableBootstrapLog\");\n }\n\n static create<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings,\n disableComponentsScan: true\n });\n }\n\n static build<App = TsED.Application, Router = TsED.Router>(\n module: Type<any>,\n {adapter, ...settings}: PlatformBuilderSettings<App, Router>\n ) {\n return new PlatformBuilder(adapter, module, settings);\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n const configuration = getConfiguration(settings, module);\n const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;\n\n if (!disableComponentsScan) {\n const {importProviders} = await import(\"@tsed/components-scan\");\n await importProviders(configuration);\n }\n\n return this.build<App, Router>(module, configuration).bootstrap();\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => void;\n callback(req: IncomingMessage, res: ServerResponse): void;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.callback()(req, res);\n }\n\n return this.app.callback();\n }\n\n log(...data: any[]) {\n return !this.disableBootstrapLog && this.logger.info(...data, this.diff());\n }\n\n /**\n * Add classes to the components list\n * @param classes\n * @deprecated\n */\n public addComponents(classes: any | any[]) {\n this.settings.set(\"componentsScan\", this.settings.get(\"componentsScan\", []).concat(classes));\n\n return this;\n }\n\n /**\n * Add classes decorated by @@Controller@@ to components container.\n *\n * ### Example\n *\n * ```typescript\n * @Controller('/ctrl')\n * class MyController{\n * }\n *\n * platform.addControllers('/rest', [MyController])\n * ```\n *\n * ::: tip\n * If the MyController class isn't decorated, the class will be ignored.\n * :::\n *\n * @param {string} endpoint\n * @param {any[]} controllers\n */\n public addControllers(endpoint: string, controllers: TokenProvider | TokenProvider[]) {\n [].concat(controllers).forEach((token) => {\n this.settings.routes.push({token, route: endpoint});\n });\n }\n\n public async runLifecycle() {\n setLoggerConfiguration(this.injector);\n\n await this.loadInjector();\n\n this.#adapter.useContext && this.#adapter.useContext();\n this.#adapter.useRouter && this.#adapter.useRouter();\n\n await this.loadRoutes();\n await this.logRoutes();\n\n return this;\n }\n\n async loadInjector() {\n const {injector} = this;\n this.log(\"Build providers\");\n\n await injector.loadModule(this.#rootModule);\n\n this.log(\"Settings and injector loaded...\");\n\n await this.callHook(\"$afterInit\");\n }\n\n async listen(network = true) {\n if (!this.#promise) {\n await this.bootstrap();\n }\n\n await this.callHook(\"$beforeListen\");\n\n if (network) {\n await this.listenServers();\n }\n\n await this.callHook(\"$afterListen\");\n\n await this.ready();\n }\n\n async stop() {\n await this.callHook(\"$onDestroy\");\n await this.injector.destroy();\n\n this.#listeners.map((server) => {\n return new Promise((resolve) => server.close(() => resolve(undefined)));\n });\n }\n\n public async ready() {\n const {startedAt} = this;\n\n await this.callHook(\"$onReady\");\n await this.injector.emit(\"$onServerReady\");\n\n this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);\n }\n\n async callHook(hook: string, ...args: any[]) {\n const {injector} = this;\n\n if (!this.disableBootstrapLog) {\n injector.logger.debug(`\\x1B[1mCall hook ${hook}\\x1B[22m`);\n }\n\n // Load middlewares for the given hook\n this.loadMiddlewaresFor(hook);\n\n // call hooks added by providers\n await injector.emit(hook, ...args);\n }\n\n async loadStatics(hook: string): Promise<void> {\n const statics = this.settings.get<PlatformStaticsSettings>(\"statics\");\n\n getStaticsOptions(statics).forEach(({path, options}) => {\n if (options.hook === hook) {\n this.platform.app.statics(path, options);\n }\n });\n }\n\n useProvider(token: Type<any>, settings?: Partial<ProviderOpts>) {\n this.injector.addProvider(token, settings);\n\n return this;\n }\n\n async bootstrap() {\n this.#promise = this.#promise || this.runLifecycle();\n\n return this.#promise;\n }\n\n protected async loadRoutes() {\n this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());\n\n // istanbul ignore next\n if (this.settings.get(\"logger.level\") !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\n }\n\n if (this.settings.get(\"acceptMimes\", []).length) {\n this.app.use(GlobalAcceptMimesMiddleware);\n }\n\n this.log(\"Load routes\");\n\n if (this.rootModule.$beforeRoutesInit) {\n await this.rootModule.$beforeRoutesInit();\n this.rootModule.$beforeRoutesInit = () => {};\n }\n\n await this.loadStatics(\"$beforeRoutesInit\");\n await this.callHook(\"$beforeRoutesInit\");\n\n const routes = this.injector.settings.get<Route[]>(\"routes\");\n\n this.platform.addRoutes(routes);\n\n await this.callHook(\"$onRoutesInit\");\n\n await this.loadStatics(\"$afterRoutesInit\");\n\n await this.callHook(\"$afterRoutesInit\");\n\n this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());\n }\n\n protected diff() {\n const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);\n this.current = new Date();\n return ms;\n }\n\n /**\n * Load middlewares from configuration for the given hook\n * @param hook\n * @protected\n */\n protected loadMiddlewaresFor(hook: string): void {\n return getMiddlewaresForHook(hook, this.settings, \"$beforeRoutesInit\").forEach(({use}) => {\n this.app.use(use);\n });\n }\n\n protected createHttpServers() {\n this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(\n Boolean\n ) as any[];\n }\n\n protected async listenServers(): Promise<void> {\n this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));\n }\n\n protected async logRoutes() {\n const {logger, platform} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.get(\"logger.disableRoutesSummary\") && !this.disableBootstrapLog) {\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", platform.getRoutes())));\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":";;;AACA,iCAAyE;
|
|
1
|
+
{"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":";;;AACA,iCAAyE;AAKzE,+CAA0C;AAE1C,MAAsB,eAAe;IACnC;;OAEG;IACH,SAAS,CAAiB;IAC1B;;OAEG;IACH,MAAM,CAAa;IACnB,gBAAgB,CAAsB;IACtC,eAAe,CAAsB;IACrC,SAAS,CAAa;IACtB,UAAU,CAAa;CAwBxB;AApCD,0CAoCC;AAMD,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,oBAAe,CAAC;IACvB,QAAQ,EAAE,yBAAW;CACtB,CAAC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, registerProvider} from \"@tsed/di\";\nimport {IncomingMessage, ServerResponse} from \"http\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {RouterOptions} from \"express\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\nexport abstract class PlatformAdapter<App = TsED.Application, Router = TsED.Router> {\n /**\n * Load providers in top priority\n */\n providers: ProviderOpts[];\n /**\n * Called after the injector instantiation\n */\n onInit?: () => any;\n beforeLoadRoutes?: () => Promise<any>;\n afterLoadRoutes?: () => Promise<any>;\n useRouter?: () => any;\n useContext?: () => any;\n\n abstract app(): {app: App; callback(): (req: IncomingMessage, res: ServerResponse) => void};\n\n abstract router(routerOptions?: Partial<RouterOptions>): {router: Router; callback(): any};\n /**\n * Return the statics middlewares\n * @param endpoint\n * @param options\n */\n abstract statics(endpoint: string, options: PlatformStaticsOptions): any;\n\n /**\n * Return the multipart middleware\n * @param options\n */\n abstract multipart(options: PlatformMulterSettings): PlatformMulter;\n\n /**\n * Return the body parser for the given\n * @param type\n * @param opts\n */\n abstract bodyParser(type: string, opts?: Record<string, any>): any;\n}\n\nexport interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {\n adapter?: Type<PlatformAdapter<App, Router>>;\n}\n\nregisterProvider({\n provide: PlatformAdapter,\n deps: [InjectorService],\n useClass: FakeAdapter\n});\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { nameOf } from "@tsed/core";
|
|
2
|
-
import { colors,
|
|
2
|
+
import { colors, setLoggerConfiguration } from "@tsed/di";
|
|
3
3
|
import { getMiddlewaresForHook } from "@tsed/platform-middlewares";
|
|
4
4
|
import { GlobalAcceptMimesMiddleware } from "../middlewares/GlobalAcceptMimesMiddleware.js";
|
|
5
5
|
import { Platform } from "../services/Platform.js";
|
|
@@ -115,10 +115,7 @@ export class PlatformBuilder {
|
|
|
115
115
|
if (req && res) {
|
|
116
116
|
return this.callback()(req, res);
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
return (req, res) => {
|
|
120
|
-
runInContext(undefined, () => cb(req, res), this.injector);
|
|
121
|
-
};
|
|
118
|
+
return this.app.callback();
|
|
122
119
|
}
|
|
123
120
|
log(...data) {
|
|
124
121
|
return !this.disableBootstrapLog && this.logger.info(...data, this.diff());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAO,MAAM,YAAY,CAAC;AACxC,OAAO,EAAC,MAAM,EAAiC,YAAY,EAAE,sBAAsB,EAAgB,MAAM,UAAU,CAAC;AACpH,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAKjE,OAAO,EAAC,2BAA2B,EAAC,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,eAAe,EAA0B,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,eAAe;IACnB,MAAM,CAAC,OAAO,CAAkC;IAE9C,IAAI,GAAW,EAAE,CAAC;IACjB,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;IACtB,SAAS,CAAkB;IAC3B,WAAW,CAAY;IACvB,QAAQ,CAA+B;IAChD,QAAQ,CAAgB;IACxB,QAAQ,CAA2C;IACnD,UAAU,GAA8B,EAAE,CAAC;IAE3C,YAAsB,OAAuD,EAAE,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,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC;IAES,KAAK,CAAC,SAAS;QACvB,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC;QAEhC,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAE9B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAClF,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9F;IACH,CAAC;CACF","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, runInContext, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport type Https from \"https\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {Route} from \"../interfaces/Route\";\nimport {GlobalAcceptMimesMiddleware} from \"../middlewares/GlobalAcceptMimesMiddleware\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {printRoutes} from \"../utils/printRoutes\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {\n public static adapter: Type<PlatformAdapter<any, any>>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n readonly #injector: InjectorService;\n readonly #rootModule: Type<any>;\n readonly #adapter: PlatformAdapter<App, Router>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n\n const configuration = getConfiguration(settings, module);\n const adapterKlass: Type<PlatformAdapter<App, Router>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n configuration.PLATFORM_NAME = name;\n this.name = name;\n\n this.#injector = createInjector({\n adapter: adapterKlass,\n settings: configuration\n });\n\n this.#adapter = this.#injector.get<PlatformAdapter<App, Router>>(PlatformAdapter)!;\n\n this.createHttpServers();\n\n this.#adapter.onInit && this.#adapter.onInit();\n\n this.log(\"Injector created...\");\n }\n\n get injector(): InjectorService {\n return this.#injector;\n }\n\n get rootModule(): any {\n return this.#injector.get(this.#rootModule);\n }\n\n get app(): PlatformApplication<App, Router> {\n return this.injector.get<PlatformApplication<App, Router>>(PlatformApplication)!;\n }\n\n get platform() {\n return this.injector.get<Platform>(Platform)!;\n }\n\n get adapter() {\n return this.#adapter;\n }\n\n /**\n * Return the settings configured by the decorator @@Configuration@@.\n *\n * ```typescript\n * @Configuration({\n * rootDir: Path.resolve(__dirname),\n * port: 8000,\n * httpsPort: 8080,\n * mount: {\n * \"/rest\": \"${rootDir}/controllers/**\\/*.js\"\n * }\n * })\n * export class Server {\n * $onInit(){\n * console.log(this.settings); // {rootDir, port, httpsPort,...}\n * }\n * }\n * ```\n *\n * @returns {PlatformConfiguration}\n */\n get settings() {\n return this.injector.settings;\n }\n\n get logger() {\n return this.injector.logger;\n }\n\n get disableBootstrapLog() {\n return this.settings.get(\"logger.disableBootstrapLog\");\n }\n\n static create<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings,\n disableComponentsScan: true\n });\n }\n\n static build<App = TsED.Application, Router = TsED.Router>(\n module: Type<any>,\n {adapter, ...settings}: PlatformBuilderSettings<App, Router>\n ) {\n return new PlatformBuilder(adapter, module, settings);\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n const configuration = getConfiguration(settings, module);\n const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;\n\n if (!disableComponentsScan) {\n const {importProviders} = await import(\"@tsed/components-scan\");\n await importProviders(configuration);\n }\n\n return this.build<App, Router>(module, configuration).bootstrap();\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => void;\n callback(req: IncomingMessage, res: ServerResponse): void;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.callback()(req, res);\n }\n\n const cb = this.app.callback();\n\n return (req: IncomingMessage, res: ServerResponse) => {\n runInContext(undefined, () => cb(req, res), this.injector);\n };\n }\n\n log(...data: any[]) {\n return !this.disableBootstrapLog && this.logger.info(...data, this.diff());\n }\n\n /**\n * Add classes to the components list\n * @param classes\n * @deprecated\n */\n public addComponents(classes: any | any[]) {\n this.settings.set(\"componentsScan\", this.settings.get(\"componentsScan\", []).concat(classes));\n\n return this;\n }\n\n /**\n * Add classes decorated by @@Controller@@ to components container.\n *\n * ### Example\n *\n * ```typescript\n * @Controller('/ctrl')\n * class MyController{\n * }\n *\n * platform.addControllers('/rest', [MyController])\n * ```\n *\n * ::: tip\n * If the MyController class isn't decorated, the class will be ignored.\n * :::\n *\n * @param {string} endpoint\n * @param {any[]} controllers\n */\n public addControllers(endpoint: string, controllers: TokenProvider | TokenProvider[]) {\n [].concat(controllers).forEach((token) => {\n this.settings.routes.push({token, route: endpoint});\n });\n }\n\n public async runLifecycle() {\n setLoggerConfiguration(this.injector);\n\n await this.loadInjector();\n\n this.#adapter.useContext && this.#adapter.useContext();\n this.#adapter.useRouter && this.#adapter.useRouter();\n\n await this.loadRoutes();\n await this.logRoutes();\n\n return this;\n }\n\n async loadInjector() {\n const {injector} = this;\n this.log(\"Build providers\");\n\n await injector.loadModule(this.#rootModule);\n\n this.log(\"Settings and injector loaded...\");\n\n await this.callHook(\"$afterInit\");\n }\n\n async listen(network = true) {\n if (!this.#promise) {\n await this.bootstrap();\n }\n\n await this.callHook(\"$beforeListen\");\n\n if (network) {\n await this.listenServers();\n }\n\n await this.callHook(\"$afterListen\");\n\n await this.ready();\n }\n\n async stop() {\n await this.callHook(\"$onDestroy\");\n await this.injector.destroy();\n\n this.#listeners.map((server) => {\n return new Promise((resolve) => server.close(() => resolve(undefined)));\n });\n }\n\n public async ready() {\n const {startedAt} = this;\n\n await this.callHook(\"$onReady\");\n await this.injector.emit(\"$onServerReady\");\n\n this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);\n }\n\n async callHook(hook: string, ...args: any[]) {\n const {injector} = this;\n\n if (!this.disableBootstrapLog) {\n injector.logger.debug(`\\x1B[1mCall hook ${hook}\\x1B[22m`);\n }\n\n // Load middlewares for the given hook\n this.loadMiddlewaresFor(hook);\n\n // call hooks added by providers\n await injector.emit(hook, ...args);\n }\n\n async loadStatics(hook: string): Promise<void> {\n const statics = this.settings.get<PlatformStaticsSettings>(\"statics\");\n\n getStaticsOptions(statics).forEach(({path, options}) => {\n if (options.hook === hook) {\n this.platform.app.statics(path, options);\n }\n });\n }\n\n useProvider(token: Type<any>, settings?: Partial<ProviderOpts>) {\n this.injector.addProvider(token, settings);\n\n return this;\n }\n\n async bootstrap() {\n this.#promise = this.#promise || this.runLifecycle();\n\n return this.#promise;\n }\n\n protected async loadRoutes() {\n this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());\n\n // istanbul ignore next\n if (this.settings.get(\"logger.level\") !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\n }\n\n if (this.settings.get(\"acceptMimes\", []).length) {\n this.app.use(GlobalAcceptMimesMiddleware);\n }\n\n this.log(\"Load routes\");\n\n if (this.rootModule.$beforeRoutesInit) {\n await this.rootModule.$beforeRoutesInit();\n this.rootModule.$beforeRoutesInit = () => {};\n }\n\n await this.loadStatics(\"$beforeRoutesInit\");\n await this.callHook(\"$beforeRoutesInit\");\n\n const routes = this.injector.settings.get<Route[]>(\"routes\");\n\n this.platform.addRoutes(routes);\n\n await this.callHook(\"$onRoutesInit\");\n\n await this.loadStatics(\"$afterRoutesInit\");\n\n await this.callHook(\"$afterRoutesInit\");\n\n this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());\n }\n\n protected diff() {\n const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);\n this.current = new Date();\n return ms;\n }\n\n /**\n * Load middlewares from configuration for the given hook\n * @param hook\n * @protected\n */\n protected loadMiddlewaresFor(hook: string): void {\n return getMiddlewaresForHook(hook, this.settings, \"$beforeRoutesInit\").forEach(({use}) => {\n this.app.use(use);\n });\n }\n\n protected createHttpServers() {\n this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(\n Boolean\n ) as any[];\n }\n\n protected async listenServers(): Promise<void> {\n this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));\n }\n\n protected async logRoutes() {\n const {logger, platform} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.get(\"logger.disableRoutesSummary\") && !this.disableBootstrapLog) {\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", platform.getRoutes())));\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MA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CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9F;IACH,CAAC;CACF","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, runInContext, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport type Https from \"https\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {Route} from \"../interfaces/Route\";\nimport {GlobalAcceptMimesMiddleware} from \"../middlewares/GlobalAcceptMimesMiddleware\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {printRoutes} from \"../utils/printRoutes\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {\n public static adapter: Type<PlatformAdapter<any, any>>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n readonly #injector: InjectorService;\n readonly #rootModule: Type<any>;\n readonly #adapter: PlatformAdapter<App, Router>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n\n const configuration = getConfiguration(settings, module);\n const adapterKlass: Type<PlatformAdapter<App, Router>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n configuration.PLATFORM_NAME = name;\n this.name = name;\n\n this.#injector = createInjector({\n adapter: adapterKlass,\n settings: configuration\n });\n\n this.#adapter = this.#injector.get<PlatformAdapter<App, Router>>(PlatformAdapter)!;\n\n this.createHttpServers();\n\n this.#adapter.onInit && this.#adapter.onInit();\n\n this.log(\"Injector created...\");\n }\n\n get injector(): InjectorService {\n return this.#injector;\n }\n\n get rootModule(): any {\n return this.#injector.get(this.#rootModule);\n }\n\n get app(): PlatformApplication<App, Router> {\n return this.injector.get<PlatformApplication<App, Router>>(PlatformApplication)!;\n }\n\n get platform() {\n return this.injector.get<Platform>(Platform)!;\n }\n\n get adapter() {\n return this.#adapter;\n }\n\n /**\n * Return the settings configured by the decorator @@Configuration@@.\n *\n * ```typescript\n * @Configuration({\n * rootDir: Path.resolve(__dirname),\n * port: 8000,\n * httpsPort: 8080,\n * mount: {\n * \"/rest\": \"${rootDir}/controllers/**\\/*.js\"\n * }\n * })\n * export class Server {\n * $onInit(){\n * console.log(this.settings); // {rootDir, port, httpsPort,...}\n * }\n * }\n * ```\n *\n * @returns {PlatformConfiguration}\n */\n get settings() {\n return this.injector.settings;\n }\n\n get logger() {\n return this.injector.logger;\n }\n\n get disableBootstrapLog() {\n return this.settings.get(\"logger.disableBootstrapLog\");\n }\n\n static create<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings,\n disableComponentsScan: true\n });\n }\n\n static build<App = TsED.Application, Router = TsED.Router>(\n module: Type<any>,\n {adapter, ...settings}: PlatformBuilderSettings<App, Router>\n ) {\n return new PlatformBuilder(adapter, module, settings);\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n const configuration = getConfiguration(settings, module);\n const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;\n\n if (!disableComponentsScan) {\n const {importProviders} = await import(\"@tsed/components-scan\");\n await importProviders(configuration);\n }\n\n return this.build<App, Router>(module, configuration).bootstrap();\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => void;\n callback(req: IncomingMessage, res: ServerResponse): void;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.callback()(req, res);\n }\n\n return this.app.callback();\n }\n\n log(...data: any[]) {\n return !this.disableBootstrapLog && this.logger.info(...data, this.diff());\n }\n\n /**\n * Add classes to the components list\n * @param classes\n * @deprecated\n */\n public addComponents(classes: any | any[]) {\n this.settings.set(\"componentsScan\", this.settings.get(\"componentsScan\", []).concat(classes));\n\n return this;\n }\n\n /**\n * Add classes decorated by @@Controller@@ to components container.\n *\n * ### Example\n *\n * ```typescript\n * @Controller('/ctrl')\n * class MyController{\n * }\n *\n * platform.addControllers('/rest', [MyController])\n * ```\n *\n * ::: tip\n * If the MyController class isn't decorated, the class will be ignored.\n * :::\n *\n * @param {string} endpoint\n * @param {any[]} controllers\n */\n public addControllers(endpoint: string, controllers: TokenProvider | TokenProvider[]) {\n [].concat(controllers).forEach((token) => {\n this.settings.routes.push({token, route: endpoint});\n });\n }\n\n public async runLifecycle() {\n setLoggerConfiguration(this.injector);\n\n await this.loadInjector();\n\n this.#adapter.useContext && this.#adapter.useContext();\n this.#adapter.useRouter && this.#adapter.useRouter();\n\n await this.loadRoutes();\n await this.logRoutes();\n\n return this;\n }\n\n async loadInjector() {\n const {injector} = this;\n this.log(\"Build providers\");\n\n await injector.loadModule(this.#rootModule);\n\n this.log(\"Settings and injector loaded...\");\n\n await this.callHook(\"$afterInit\");\n }\n\n async listen(network = true) {\n if (!this.#promise) {\n await this.bootstrap();\n }\n\n await this.callHook(\"$beforeListen\");\n\n if (network) {\n await this.listenServers();\n }\n\n await this.callHook(\"$afterListen\");\n\n await this.ready();\n }\n\n async stop() {\n await this.callHook(\"$onDestroy\");\n await this.injector.destroy();\n\n this.#listeners.map((server) => {\n return new Promise((resolve) => server.close(() => resolve(undefined)));\n });\n }\n\n public async ready() {\n const {startedAt} = this;\n\n await this.callHook(\"$onReady\");\n await this.injector.emit(\"$onServerReady\");\n\n this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);\n }\n\n async callHook(hook: string, ...args: any[]) {\n const {injector} = this;\n\n if (!this.disableBootstrapLog) {\n injector.logger.debug(`\\x1B[1mCall hook ${hook}\\x1B[22m`);\n }\n\n // Load middlewares for the given hook\n this.loadMiddlewaresFor(hook);\n\n // call hooks added by providers\n await injector.emit(hook, ...args);\n }\n\n async loadStatics(hook: string): Promise<void> {\n const statics = this.settings.get<PlatformStaticsSettings>(\"statics\");\n\n getStaticsOptions(statics).forEach(({path, options}) => {\n if (options.hook === hook) {\n this.platform.app.statics(path, options);\n }\n });\n }\n\n useProvider(token: Type<any>, settings?: Partial<ProviderOpts>) {\n this.injector.addProvider(token, settings);\n\n return this;\n }\n\n async bootstrap() {\n this.#promise = this.#promise || this.runLifecycle();\n\n return this.#promise;\n }\n\n protected async loadRoutes() {\n this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());\n\n // istanbul ignore next\n if (this.settings.get(\"logger.level\") !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\n }\n\n if (this.settings.get(\"acceptMimes\", []).length) {\n this.app.use(GlobalAcceptMimesMiddleware);\n }\n\n this.log(\"Load routes\");\n\n if (this.rootModule.$beforeRoutesInit) {\n await this.rootModule.$beforeRoutesInit();\n this.rootModule.$beforeRoutesInit = () => {};\n }\n\n await this.loadStatics(\"$beforeRoutesInit\");\n await this.callHook(\"$beforeRoutesInit\");\n\n const routes = this.injector.settings.get<Route[]>(\"routes\");\n\n this.platform.addRoutes(routes);\n\n await this.callHook(\"$onRoutesInit\");\n\n await this.loadStatics(\"$afterRoutesInit\");\n\n await this.callHook(\"$afterRoutesInit\");\n\n this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());\n }\n\n protected diff() {\n const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);\n this.current = new Date();\n return ms;\n }\n\n /**\n * Load middlewares from configuration for the given hook\n * @param hook\n * @protected\n */\n protected loadMiddlewaresFor(hook: string): void {\n return getMiddlewaresForHook(hook, this.settings, \"$beforeRoutesInit\").forEach(({use}) => {\n this.app.use(use);\n });\n }\n\n protected createHttpServers() {\n this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(\n Boolean\n ) as any[];\n }\n\n protected async listenServers(): Promise<void> {\n this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));\n }\n\n protected async logRoutes() {\n const {logger, platform} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.get(\"logger.disableRoutesSummary\") && !this.disableBootstrapLog) {\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", platform.getRoutes())));\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAgB,gBAAgB,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAgB,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAKzE,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,MAAM,OAAgB,eAAe;IACnC;;OAEG;IACH,SAAS,CAAiB;IAC1B;;OAEG;IACH,MAAM,CAAa;IACnB,gBAAgB,CAAsB;IACtC,eAAe,CAAsB;IACrC,SAAS,CAAa;IACtB,UAAU,CAAa;CAwBxB;AAMD,gBAAgB,CAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,eAAe,CAAC;IACvB,QAAQ,EAAE,WAAW;CACtB,CAAC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, registerProvider} from \"@tsed/di\";\nimport {IncomingMessage, ServerResponse} from \"http\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {RouterOptions} from \"express\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\nexport abstract class PlatformAdapter<App = TsED.Application, Router = TsED.Router> {\n /**\n * Load providers in top priority\n */\n providers: ProviderOpts[];\n /**\n * Called after the injector instantiation\n */\n onInit?: () => any;\n beforeLoadRoutes?: () => Promise<any>;\n afterLoadRoutes?: () => Promise<any>;\n useRouter?: () => any;\n useContext?: () => any;\n\n abstract app(): {app: App; callback(): (req: IncomingMessage, res: ServerResponse) => void};\n\n abstract router(routerOptions?: Partial<RouterOptions>): {router: Router; callback(): any};\n /**\n * Return the statics middlewares\n * @param endpoint\n * @param options\n */\n abstract statics(endpoint: string, options: PlatformStaticsOptions): any;\n\n /**\n * Return the multipart middleware\n * @param options\n */\n abstract multipart(options: PlatformMulterSettings): PlatformMulter;\n\n /**\n * Return the body parser for the given\n * @param type\n * @param opts\n */\n abstract bodyParser(type: string, opts?: Record<string, any>): any;\n}\n\nexport interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {\n adapter?: Type<PlatformAdapter<App, Router>>;\n}\n\nregisterProvider({\n provide: PlatformAdapter,\n deps: [InjectorService],\n useClass: FakeAdapter\n});\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Type } from "@tsed/core";
|
|
2
3
|
import { ProviderOpts } from "@tsed/di";
|
|
4
|
+
import { IncomingMessage, ServerResponse } from "http";
|
|
3
5
|
import { PlatformMulter, PlatformMulterSettings } from "../config/interfaces/PlatformMulterSettings";
|
|
4
6
|
import { PlatformStaticsOptions } from "../config/interfaces/PlatformStaticsSettings";
|
|
5
7
|
import { RouterOptions } from "express";
|
|
@@ -18,7 +20,7 @@ export declare abstract class PlatformAdapter<App = TsED.Application, Router = T
|
|
|
18
20
|
useContext?: () => any;
|
|
19
21
|
abstract app(): {
|
|
20
22
|
app: App;
|
|
21
|
-
callback():
|
|
23
|
+
callback(): (req: IncomingMessage, res: ServerResponse) => void;
|
|
22
24
|
};
|
|
23
25
|
abstract router(routerOptions?: Partial<RouterOptions>): {
|
|
24
26
|
router: Router;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/common",
|
|
3
|
-
"version": "6.128.
|
|
3
|
+
"version": "6.128.2",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -62,22 +62,22 @@
|
|
|
62
62
|
}
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@tsed/components-scan": "6.128.
|
|
66
|
-
"@tsed/core": "6.128.
|
|
67
|
-
"@tsed/di": "6.128.
|
|
68
|
-
"@tsed/exceptions": "6.128.
|
|
69
|
-
"@tsed/json-mapper": "6.128.
|
|
65
|
+
"@tsed/components-scan": "6.128.2",
|
|
66
|
+
"@tsed/core": "6.128.2",
|
|
67
|
+
"@tsed/di": "6.128.2",
|
|
68
|
+
"@tsed/exceptions": "6.128.2",
|
|
69
|
+
"@tsed/json-mapper": "6.128.2",
|
|
70
70
|
"@tsed/logger": ">=6.2.0",
|
|
71
71
|
"@tsed/logger-file": ">=6.2.0",
|
|
72
|
-
"@tsed/perf": "6.128.
|
|
73
|
-
"@tsed/platform-cache": "6.128.
|
|
74
|
-
"@tsed/platform-exceptions": "6.128.
|
|
75
|
-
"@tsed/platform-log-middleware": "6.128.
|
|
76
|
-
"@tsed/platform-middlewares": "6.128.
|
|
77
|
-
"@tsed/platform-params": "6.128.
|
|
78
|
-
"@tsed/platform-response-filter": "6.128.
|
|
79
|
-
"@tsed/platform-views": "6.128.
|
|
80
|
-
"@tsed/schema": "6.128.
|
|
72
|
+
"@tsed/perf": "6.128.2",
|
|
73
|
+
"@tsed/platform-cache": "6.128.2",
|
|
74
|
+
"@tsed/platform-exceptions": "6.128.2",
|
|
75
|
+
"@tsed/platform-log-middleware": "6.128.2",
|
|
76
|
+
"@tsed/platform-middlewares": "6.128.2",
|
|
77
|
+
"@tsed/platform-params": "6.128.2",
|
|
78
|
+
"@tsed/platform-response-filter": "6.128.2",
|
|
79
|
+
"@tsed/platform-views": "6.128.2",
|
|
80
|
+
"@tsed/schema": "6.128.2",
|
|
81
81
|
"@types/json-schema": "7.0.11",
|
|
82
82
|
"@types/on-finished": "2.3.1",
|
|
83
83
|
"on-finished": "2.4.1",
|