@tsed/common 6.91.0 → 6.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/lib/cjs/builder/PlatformBuilder.d.ts +2 -1
  2. package/lib/cjs/builder/PlatformBuilder.js +12 -5
  3. package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
  4. package/lib/cjs/config/interfaces/index.d.ts +10 -1
  5. package/lib/cjs/config/interfaces/index.js.map +1 -1
  6. package/lib/cjs/config/services/PlatformConfiguration.d.ts +9 -13
  7. package/lib/cjs/config/services/PlatformConfiguration.js +12 -29
  8. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
  9. package/lib/cjs/decorators/httpServer.d.ts +1 -0
  10. package/lib/cjs/decorators/httpServer.js +1 -0
  11. package/lib/cjs/decorators/httpServer.js.map +1 -1
  12. package/lib/cjs/decorators/httpsServer.d.ts +1 -0
  13. package/lib/cjs/decorators/httpsServer.js +1 -0
  14. package/lib/cjs/decorators/httpsServer.js.map +1 -1
  15. package/lib/cjs/services/PlatformTest.js +2 -9
  16. package/lib/cjs/services/PlatformTest.js.map +1 -1
  17. package/lib/cjs/utils/createHttpServer.d.ts +3 -2
  18. package/lib/cjs/utils/createHttpServer.js +23 -24
  19. package/lib/cjs/utils/createHttpServer.js.map +1 -1
  20. package/lib/cjs/utils/createHttpsServer.d.ts +3 -2
  21. package/lib/cjs/utils/createHttpsServer.js +23 -25
  22. package/lib/cjs/utils/createHttpsServer.js.map +1 -1
  23. package/lib/cjs/utils/createInjector.js +0 -4
  24. package/lib/cjs/utils/createInjector.js.map +1 -1
  25. package/lib/cjs/utils/listenServer.d.ts +6 -9
  26. package/lib/cjs/utils/listenServer.js +11 -7
  27. package/lib/cjs/utils/listenServer.js.map +1 -1
  28. package/lib/esm/builder/PlatformBuilder.js +13 -6
  29. package/lib/esm/builder/PlatformBuilder.js.map +1 -1
  30. package/lib/esm/config/interfaces/index.js.map +1 -1
  31. package/lib/esm/config/services/PlatformConfiguration.js +12 -29
  32. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -1
  33. package/lib/esm/decorators/httpServer.js +1 -0
  34. package/lib/esm/decorators/httpServer.js.map +1 -1
  35. package/lib/esm/decorators/httpsServer.js +1 -0
  36. package/lib/esm/decorators/httpsServer.js.map +1 -1
  37. package/lib/esm/services/PlatformTest.js +2 -9
  38. package/lib/esm/services/PlatformTest.js.map +1 -1
  39. package/lib/esm/utils/createHttpServer.js +22 -22
  40. package/lib/esm/utils/createHttpServer.js.map +1 -1
  41. package/lib/esm/utils/createHttpsServer.js +22 -23
  42. package/lib/esm/utils/createHttpsServer.js.map +1 -1
  43. package/lib/esm/utils/createInjector.js +0 -4
  44. package/lib/esm/utils/createInjector.js.map +1 -1
  45. package/lib/esm/utils/listenServer.js +11 -7
  46. package/lib/esm/utils/listenServer.js.map +1 -1
  47. package/lib/types/builder/PlatformBuilder.d.ts +2 -1
  48. package/lib/types/config/interfaces/index.d.ts +10 -1
  49. package/lib/types/config/services/PlatformConfiguration.d.ts +9 -13
  50. package/lib/types/decorators/httpServer.d.ts +1 -0
  51. package/lib/types/decorators/httpsServer.d.ts +1 -0
  52. package/lib/types/utils/createHttpServer.d.ts +3 -2
  53. package/lib/types/utils/createHttpsServer.d.ts +3 -2
  54. package/lib/types/utils/listenServer.d.ts +6 -9
  55. package/package.json +15 -15
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,MAAM,EAAkB,MAAM,UAAU,CAAC;AAClE,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAyB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,O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AI,CAAC;YACnB,CAAC;YACD,IAAI,CAAC,IAAS;gBACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,UAAiD,EAAE;;QAC7E,MAAM,KAAK,GAAG;YACZ,OAAO,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,OAAO,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,OAAO,CAAA,IAAI,YAAY,CAAC,aAAa,EAAE;YAC7F,QAAQ,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,0CAAE,QAAQ,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,QAAQ,CAAA,IAAI,YAAY,CAAC,cAAc,EAAE;SACnG,CAAC;QAEF,OAAO,IAAI,eAAe,CAAC;YACzB,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {createContainer, DITest, InjectorService} from \"@tsed/di\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../interfaces/PlatformAdapter\";\nimport {Type} from \"@tsed/core\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static adapter: Type<PlatformAdapter>;\n\n static async create(settings: Partial<TsED.Configuration> = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n const container = createContainer();\n\n await DITest.injector.load(container);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n providers: [],\n settings: DITest.configure(settings)\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: any;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n instance = await PlatformBuilder.build(mod, settings).bootstrap();\n\n if (!listen) {\n await instance.callHook(\"$beforeListen\");\n await instance.callHook(\"$afterListen\");\n await instance.ready();\n } else {\n await instance.listen();\n }\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return require(\"accepts\")(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,MAAM,EAAkB,MAAM,UAAU,CAAC;AAClE,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAyB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,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I,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,UAAiD,EAAE;;QAC7E,MAAM,KAAK,GAAG;YACZ,OAAO,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,OAAO,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,OAAO,CAAA,IAAI,YAAY,CAAC,aAAa,EAAE;YAC7F,QAAQ,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,0CAAE,QAAQ,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,QAAQ,CAAA,IAAI,YAAY,CAAC,cAAc,EAAE;SACnG,CAAC;QAEF,OAAO,IAAI,eAAe,CAAC;YACzB,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {createContainer, DITest, InjectorService} from \"@tsed/di\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../interfaces/PlatformAdapter\";\nimport {Type} from \"@tsed/core\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static adapter: Type<PlatformAdapter>;\n\n static async create(settings: Partial<TsED.Configuration> = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n const container = createContainer();\n\n await DITest.injector.load(container);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n providers: [],\n settings: DITest.configure({httpPort: false, httpsPort: false, ...settings})\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: PlatformBuilder;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n instance = await PlatformBuilder.build(mod, settings).bootstrap();\n await instance.listen(!!listen);\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return require(\"accepts\")(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
@@ -1,29 +1,29 @@
1
- import { ProviderScope, registerProvider } from "@tsed/di";
1
+ import { ProviderScope } from "@tsed/di";
2
+ import { getHostInfoFromPort } from "@tsed/core";
2
3
  import Http from "http";
3
- import { PlatformApplication } from "../services/PlatformApplication";
4
4
  import { HttpServer } from "../decorators/httpServer";
5
5
  import { listenServer } from "./listenServer";
6
- export function createHttpServer(injector) {
7
- injector.invoke(HttpServer);
8
- }
9
- registerProvider({
10
- provide: HttpServer,
11
- deps: [PlatformApplication],
12
- scope: ProviderScope.SINGLETON,
13
- global: true,
14
- useFactory(platformApplication) {
15
- return Http.createServer(platformApplication.callback());
16
- }
17
- });
18
- export async function listenHttpServer(injector) {
6
+ export function createHttpServer(injector, requestListener) {
19
7
  const { settings } = injector;
20
- const server = injector.get(HttpServer);
21
- if (settings.httpPort !== false && server) {
22
- const { address, port } = settings.getHttpPort();
23
- injector.logger.debug(`Start server on http://${address}:${port}`);
24
- const options = await listenServer(server, { address, port });
25
- settings.setHttpPort(options);
26
- injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
8
+ const httpPort = settings.getRaw("httpPort");
9
+ const httpOptions = settings.getRaw("httpOptions");
10
+ const server = httpPort !== false ? Http.createServer(httpOptions, requestListener) : null;
11
+ injector.addProvider(HttpServer, {
12
+ scope: ProviderScope.SINGLETON,
13
+ useValue: server
14
+ });
15
+ injector.addProvider(Http.Server, {
16
+ scope: ProviderScope.SINGLETON,
17
+ useValue: server
18
+ });
19
+ injector.invoke(HttpServer);
20
+ injector.invoke(Http.Server);
21
+ if (httpPort !== false) {
22
+ const hostInfo = getHostInfoFromPort("http", httpPort);
23
+ return async () => {
24
+ const resolvedHostInfo = await listenServer(injector, server, hostInfo);
25
+ settings.setRaw("httpPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
26
+ };
27
27
  }
28
28
  }
29
29
  //# sourceMappingURL=createHttpServer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createHttpServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,MAAM,UAAU,gBAAgB,CAAC,QAAyB;IACxD,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC;AAED,gBAAgB,CAAC;IACf,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,CAAC,mBAAmB,CAAC;IAC3B,KAAK,EAAE,aAAa,CAAC,SAAS;IAC9B,MAAM,EAAE,IAAI;IACZ,UAAU,CAAC,mBAAwC;QACjD,OAAO,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,QAAyB;IAC9D,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAa,UAAU,CAAC,CAAC;IAEpD,IAAI,QAAQ,CAAC,QAAQ,KAAK,KAAK,IAAI,MAAM,EAAE;QACzC,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC/C,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC;QAEnE,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;QAC5D,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAE9B,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACpF;AACH,CAAC","sourcesContent":["import {InjectorService, ProviderScope, registerProvider} from \"@tsed/di\";\nimport Http from \"http\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {HttpServer} from \"../decorators/httpServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpServer(injector: InjectorService): void {\n injector.invoke(HttpServer);\n}\n\nregisterProvider({\n provide: HttpServer,\n deps: [PlatformApplication],\n scope: ProviderScope.SINGLETON,\n global: true,\n useFactory(platformApplication: PlatformApplication) {\n return Http.createServer(platformApplication.callback());\n }\n});\n\nexport async function listenHttpServer(injector: InjectorService) {\n const {settings} = injector;\n const server = injector.get<HttpServer>(HttpServer);\n\n if (settings.httpPort !== false && server) {\n const {address, port} = settings.getHttpPort();\n injector.logger.debug(`Start server on http://${address}:${port}`);\n\n const options = await listenServer(server, {address, port});\n settings.setHttpPort(options);\n\n injector.logger.info(`Listen server on http://${options.address}:${options.port}`);\n }\n}\n"]}
1
+ {"version":3,"file":"createHttpServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAC,MAAM,UAAU,CAAC;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,YAAY,CAAC;AAC/C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,MAAM,UAAU,gBAAgB,CAAC,QAAyB,EAAE,eAAqC;IAC/F,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAEnD,MAAM,MAAM,GAAG,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3F,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE;QAC/B,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE;QAChC,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE7B,IAAI,QAAQ,KAAK,KAAK,EAAE;QACtB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEvD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,MAAqB,EAAE,QAAQ,CAAC,CAAC;YACvF,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;QACtF,CAAC,CAAC;KACH;AACH,CAAC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Http from \"http\";\nimport {HttpServer} from \"../decorators/httpServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpServer(injector: InjectorService, requestListener: Http.RequestListener) {\n const {settings} = injector;\n const httpPort = settings.getRaw(\"httpPort\");\n const httpOptions = settings.getRaw(\"httpOptions\");\n\n const server = httpPort !== false ? Http.createServer(httpOptions, requestListener) : null;\n\n injector.addProvider(HttpServer, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.addProvider(Http.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(HttpServer);\n injector.invoke(Http.Server);\n\n if (httpPort !== false) {\n const hostInfo = getHostInfoFromPort(\"http\", httpPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Http.Server, hostInfo);\n settings.setRaw(\"httpPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n };\n }\n}\n"]}
@@ -1,30 +1,29 @@
1
- import { Configuration, ProviderScope, registerProvider } from "@tsed/di";
1
+ import { ProviderScope } from "@tsed/di";
2
+ import { getHostInfoFromPort } from "@tsed/core";
2
3
  import Https from "https";
3
- import { PlatformApplication } from "../services/PlatformApplication";
4
4
  import { HttpsServer } from "../decorators/httpsServer";
5
5
  import { listenServer } from "./listenServer";
6
- export function createHttpsServer(injector) {
7
- injector.invoke(HttpsServer);
8
- }
9
- registerProvider({
10
- provide: HttpsServer,
11
- deps: [PlatformApplication, Configuration],
12
- scope: ProviderScope.SINGLETON,
13
- global: true,
14
- useFactory(platformApplication, settings) {
15
- const options = settings.httpsOptions;
16
- return Https.createServer(options, platformApplication.callback());
17
- }
18
- });
19
- export async function listenHttpsServer(injector) {
6
+ export function createHttpsServer(injector, requestListener) {
20
7
  const { settings } = injector;
21
- const server = injector.get(HttpsServer);
22
- if (settings.httpsPort !== false && server) {
23
- const { address, port } = settings.getHttpsPort();
24
- injector.logger.debug(`Start server on https://${address}:${port}`);
25
- const options = await listenServer(server, { address, port });
26
- settings.setHttpsPort(options);
27
- injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
8
+ const httpsPort = settings.getRaw("httpsPort");
9
+ const httpsOptions = settings.getRaw("httpsOptions");
10
+ const server = httpsPort !== false ? Https.createServer(httpsOptions, requestListener) : null;
11
+ injector.addProvider(HttpsServer, {
12
+ scope: ProviderScope.SINGLETON,
13
+ useValue: server
14
+ });
15
+ injector.addProvider(Https.Server, {
16
+ scope: ProviderScope.SINGLETON,
17
+ useValue: server
18
+ });
19
+ injector.invoke(HttpsServer);
20
+ injector.invoke(Https.Server);
21
+ if (httpsPort !== false) {
22
+ const hostInfo = getHostInfoFromPort("https", httpsPort);
23
+ return async () => {
24
+ const resolvedHostInfo = await listenServer(injector, server, hostInfo);
25
+ settings.setRaw("httpsPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
26
+ };
28
27
  }
29
28
  }
30
29
  //# sourceMappingURL=createHttpsServer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createHttpsServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpsServer.ts"],"names":[],"m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,CAAC;QAC5D,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE/B,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACrF;AACH,CAAC","sourcesContent":["import {Configuration, InjectorService, ProviderScope, registerProvider} from \"@tsed/di\";\nimport Https from \"https\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {HttpsServer} from \"../decorators/httpsServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpsServer(injector: InjectorService): void {\n injector.invoke(HttpsServer);\n}\n\nregisterProvider({\n provide: HttpsServer,\n deps: [PlatformApplication, Configuration],\n scope: ProviderScope.SINGLETON,\n global: true,\n useFactory(platformApplication: PlatformApplication, settings: Configuration) {\n const options = settings.httpsOptions!;\n\n return Https.createServer(options, platformApplication.callback());\n }\n});\n\nexport async function listenHttpsServer(injector: InjectorService) {\n const {settings} = injector;\n const server = injector.get<HttpsServer>(HttpsServer);\n\n if (settings.httpsPort !== false && server) {\n const {address, port} = settings.getHttpsPort();\n injector.logger.debug(`Start server on https://${address}:${port}`);\n\n const options = await listenServer(server, {address, port});\n settings.setHttpsPort(options);\n\n injector.logger.info(`Listen server on https://${options.address}:${options.port}`);\n }\n}\n"]}
1
+ {"version":3,"file":"createHttpsServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpsServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAC,MAAM,UAAU,CAAC;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,MAAM,UAAU,iBAAiB,CAAC,QAAyB,EAAE,eAAsC;IACjG,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAErD,MAAM,MAAM,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE9F,QAAQ,CAAC,WAAW,CAAC,WAAW,EAAE;QAChC,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE;QACjC,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE9B,IAAI,SAAS,KAAK,KAAK,EAAE;QACvB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAEzD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,MAAsB,EAAE,QAAQ,CAAC,CAAC;YACxF,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;QACvF,CAAC,CAAC;KACH;AACH,CAAC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Https from \"https\";\nimport Http from \"http\";\nimport {HttpsServer} from \"../decorators/httpsServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpsServer(injector: InjectorService, requestListener?: Http.RequestListener) {\n const {settings} = injector;\n const httpsPort = settings.getRaw(\"httpsPort\");\n const httpsOptions = settings.getRaw(\"httpsOptions\");\n\n const server = httpsPort !== false ? Https.createServer(httpsOptions, requestListener) : null;\n\n injector.addProvider(HttpsServer, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.addProvider(Https.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(HttpsServer);\n injector.invoke(Https.Server);\n\n if (httpsPort !== false) {\n const hostInfo = getHostInfoFromPort(\"https\", httpsPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Https.Server, hostInfo);\n settings.setRaw(\"httpsPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n };\n }\n}\n"]}
@@ -8,8 +8,6 @@ import { PlatformRouter } from "../services/PlatformRouter";
8
8
  import { PlatformApplication } from "../services/PlatformApplication";
9
9
  import { Platform } from "../services/Platform";
10
10
  import { PlatformRequest } from "../services/PlatformRequest";
11
- import { createHttpsServer } from "./createHttpsServer";
12
- import { createHttpServer } from "./createHttpServer";
13
11
  $log.name = "TSED";
14
12
  const DEFAULT_PROVIDERS = [
15
13
  { provide: PlatformHandler },
@@ -31,8 +29,6 @@ export function createInjector({ providers = [], settings = {} }) {
31
29
  injector.addProvider(token, provider);
32
30
  });
33
31
  injector.invoke(PlatformApplication);
34
- createHttpsServer(injector);
35
- createHttpServer(injector);
36
32
  return injector;
37
33
  }
38
34
  //# sourceMappingURL=createInjector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAa,cAAc,EAAC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAC,KAAK,EAAO,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,qBAAqB,EAAC,MAAM,0CA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D,KAAK,CAAiB,SAAS,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtE,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACrC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5B,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAE3B,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {InjectorService, IProvider, setLoggerLevel} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {toMap, Type} from \"@tsed/core\";\nimport {PlatformConfiguration} from \"../config/services/PlatformConfiguration\";\nimport {PlatformHandler} from \"../services/PlatformHandler\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\nimport {PlatformRouter} from \"../services/PlatformRouter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {createHttpsServer} from \"./createHttpsServer\";\nimport {createHttpServer} from \"./createHttpServer\";\n\n$log.name = \"TSED\";\n\nconst DEFAULT_PROVIDERS = [\n {provide: PlatformHandler},\n {provide: PlatformResponse},\n {provide: PlatformRequest},\n {provide: PlatformRouter},\n {provide: PlatformApplication},\n {provide: Platform}\n];\n\ninterface CreateInjectorOptions {\n providers?: IProvider[];\n settings?: Partial<TsED.Configuration>;\n}\n\nexport function createInjector({providers = [], settings = {}}: CreateInjectorOptions) {\n const injector = new InjectorService();\n injector.addProvider(PlatformConfiguration);\n\n injector.settings = injector.invoke(PlatformConfiguration);\n injector.logger = $log;\n injector.settings.set(settings);\n\n setLoggerLevel(injector);\n\n providers = [...DEFAULT_PROVIDERS, ...providers];\n\n toMap<any, IProvider>(providers, \"provide\").forEach((provider, token) => {\n injector.addProvider(token, provider);\n });\n\n injector.invoke(PlatformApplication);\n createHttpsServer(injector);\n createHttpServer(injector);\n\n return injector;\n}\n"]}
1
+ {"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAa,cAAc,EAAC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,qBAAqB,EAAC,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAE5D,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;AAEnB,MAAM,iBAAiB,GAAG;IACxB,EAAC,OAAO,EAAE,eAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,gBAAgB,EAAC;IAC3B,EAAC,OAAO,EAAE,eAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,cAAc,EAAC;IACzB,EAAC,OAAO,EAAE,mBAAmB,EAAC;IAC9B,EAAC,OAAO,EAAE,QAAQ,EAAC;CACpB,CAAC;AAOF,MAAM,UAAU,cAAc,CAAC,EAAC,SAAS,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAwB;IACnF,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAE5C,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEhC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEzB,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,SAAS,CAAC,CAAC;IAEjD,KAAK,CAAiB,SAAS,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtE,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAErC,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {InjectorService, IProvider, setLoggerLevel} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {toMap} from \"@tsed/core\";\nimport {PlatformConfiguration} from \"../config/services/PlatformConfiguration\";\nimport {PlatformHandler} from \"../services/PlatformHandler\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\nimport {PlatformRouter} from \"../services/PlatformRouter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\n\n$log.name = \"TSED\";\n\nconst DEFAULT_PROVIDERS = [\n {provide: PlatformHandler},\n {provide: PlatformResponse},\n {provide: PlatformRequest},\n {provide: PlatformRouter},\n {provide: PlatformApplication},\n {provide: Platform}\n];\n\ninterface CreateInjectorOptions {\n providers?: IProvider[];\n settings?: Partial<TsED.Configuration>;\n}\n\nexport function createInjector({providers = [], settings = {}}: CreateInjectorOptions) {\n const injector = new InjectorService();\n injector.addProvider(PlatformConfiguration);\n\n injector.settings = injector.invoke(PlatformConfiguration);\n injector.logger = $log;\n injector.settings.set(settings);\n\n setLoggerLevel(injector);\n\n providers = [...DEFAULT_PROVIDERS, ...providers];\n\n toMap<any, IProvider>(providers, \"provide\").forEach((provider, token) => {\n injector.addProvider(token, provider);\n });\n\n injector.invoke(PlatformApplication);\n\n return injector;\n}\n"]}
@@ -1,13 +1,17 @@
1
- export function listenServer(http, settings) {
2
- const { address, port } = settings;
1
+ export function listenServer(injector, server, hostInfo) {
2
+ const { protocol, address, port } = hostInfo;
3
+ const url = `${protocol}://${address}:${port}`;
4
+ injector.logger.debug(`Start server on ${url}`);
3
5
  const promise = new Promise((resolve, reject) => {
4
- http.on("listening", resolve);
5
- http.on("error", reject);
6
+ server.on("listening", resolve);
7
+ server.on("error", reject);
6
8
  }).then(() => {
7
- const port = http.address().port;
8
- return { address: settings.address, port };
9
+ const port = server.address().port;
10
+ const info = { ...hostInfo, port };
11
+ injector.logger.info(`Listen server on ${info.toString()}`);
12
+ return info;
9
13
  });
10
- http.listen(port, address);
14
+ server.listen(port, address);
11
15
  return promise;
12
16
  }
13
17
  //# sourceMappingURL=listenServer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"listenServer.js","sourceRoot":"","sources":["../../../src/utils/listenServer.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,YAAY,CAC1B,IAAgC,EAChC,QAAkD;IAElD,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,QAAQ,CAAC;IAEjC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACX,MAAM,IAAI,GAAI,IAAI,CAAC,OAAO,EAAU,CAAC,IAAI,CAAC;QAE1C,OAAO,EAAC,OAAO,EAAE,QAAQ,CAAC,OAAiB,EAAE,IAAI,EAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAc,CAAC,CAAC;IAElC,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import Http from \"http\";\nimport Https from \"https\";\n\nexport function listenServer(\n http: Http.Server | Https.Server,\n settings: {address: string | number; port: number}\n): Promise<{address: string; port: number}> {\n const {address, port} = settings;\n\n const promise = new Promise((resolve, reject) => {\n http.on(\"listening\", resolve);\n http.on(\"error\", reject);\n }).then(() => {\n const port = (http.address() as any).port;\n\n return {address: settings.address as string, port};\n });\n\n http.listen(port, address as any);\n\n return promise;\n}\n"]}
1
+ {"version":3,"file":"listenServer.js","sourceRoot":"","sources":["../../../src/utils/listenServer.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,YAAY,CAC1B,QAAyB,EACzB,MAAsD,EACtD,QAAgD;IAEhD,MAAM,EAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAC,GAAG,QAAQ,CAAC;IAC3C,MAAM,GAAG,GAAG,GAAG,QAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;IAC/C,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;IAEhD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAChC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACX,MAAM,IAAI,GAAI,MAAM,CAAC,OAAO,EAAU,CAAC,IAAI,CAAC;QAC5C,MAAM,IAAI,GAAG,EAAC,GAAG,QAAQ,EAAE,IAAI,EAAC,CAAC;QAEjC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAE5D,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAc,CAAC,CAAC;IAEpC,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type Http from \"http\";\nimport type Https from \"https\";\nimport type Http2 from \"http2\";\nimport {InjectorService} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\n\nexport function listenServer(\n injector: InjectorService,\n server: Http.Server | Https.Server | Http2.Http2Server,\n hostInfo: ReturnType<typeof getHostInfoFromPort>\n): Promise<ReturnType<typeof getHostInfoFromPort>> {\n const {protocol, address, port} = hostInfo;\n const url = `${protocol}://${address}:${port}`;\n injector.logger.debug(`Start server on ${url}`);\n\n const promise = new Promise((resolve, reject) => {\n server.on(\"listening\", resolve);\n server.on(\"error\", reject);\n }).then(() => {\n const port = (server.address() as any).port;\n const info = {...hostInfo, port};\n\n injector.logger.info(`Listen server on ${info.toString()}`);\n\n return info;\n });\n\n server.listen(port, address as any);\n\n return promise;\n}\n"]}
@@ -82,7 +82,7 @@ export declare class PlatformBuilder<App = TsED.Application, Router = TsED.Route
82
82
  addControllers(endpoint: string, controllers: any | string | (any | string)[]): void;
83
83
  runLifecycle(): Promise<this>;
84
84
  loadInjector(): Promise<void>;
85
- listen(): Promise<void>;
85
+ listen(network?: boolean): Promise<void>;
86
86
  stop(): Promise<void>;
87
87
  ready(): Promise<void>;
88
88
  callHook(hook: string, ...args: any[]): Promise<void>;
@@ -98,6 +98,7 @@ export declare class PlatformBuilder<App = TsED.Application, Router = TsED.Route
98
98
  * @protected
99
99
  */
100
100
  protected loadMiddlewaresFor(hook: string): void;
101
+ protected createHttpServers(): void;
101
102
  protected listenServers(): Promise<void>;
102
103
  protected logRoutes(): Promise<void>;
103
104
  }
@@ -1,11 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import { Env } from "@tsed/core";
3
- import Https from "https";
4
3
  import { ConverterSettings } from "./ConverterSettings";
5
4
  import { EndpointDirectoriesSettings } from "./EndpointDirectoriesSettings";
6
5
  import { PlatformLoggerSettings } from "./PlatformLoggerSettings";
7
6
  import { PlatformMulterSettings } from "./PlatformMulterSettings";
8
7
  import { PlatformStaticsSettings } from "./PlatformStaticsSettings";
8
+ import type Http from "http";
9
+ import type Https from "https";
9
10
  declare global {
10
11
  namespace TsED {
11
12
  interface LoggerConfiguration extends Partial<PlatformLoggerSettings> {
@@ -27,6 +28,14 @@ declare global {
27
28
  * Port number for the [HTTP.Server](https://nodejs.org/api/http.html#http_class_http_server).
28
29
  */
29
30
  httpPort: string | number | boolean;
31
+ /**
32
+ * [Https.ServerOptions](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)):
33
+ * - `key` &lt;string&gt; | &lt;string[]&gt; | [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer) | &lt;Object[]&gt;: The private key of the server in PEM format. To support multiple keys using different algorithms an array can be provided either as a plain array of key strings or an array of objects in the format `{pem: key, passphrase: passphrase}`. This option is required for ciphers that make use of private keys.
34
+ * - `passphrase` &lt;string&gt; A string containing the passphrase for the private key or pfx.
35
+ * - `cert` &lt;string&gt; | &lt;string[]&gt; | [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer) | [&lt;Buffer[]&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings, or array of Buffers containing the certificate key of the server in PEM format. (Required)
36
+ * - `ca` &lt;string&gt; | &lt;string[]&gt; | [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer) | [&lt;Buffer[]&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings, or array of Buffers of trusted certificates in PEM format. If this is omitted several well known "root" CAs (like VeriSign) will be used. These are used to authorize connections.
37
+ */
38
+ httpOptions: Http.ServerOptions;
30
39
  /**
31
40
  * Port number for the [HTTPs.Server](https://nodejs.org/api/https.html#https_class_https_server).
32
41
  */
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Env } from "@tsed/core";
2
+ import { Env, getHostInfoFromPort } from "@tsed/core";
3
3
  import { DIConfiguration } from "@tsed/di";
4
4
  import Https from "https";
5
5
  import { EndpointDirectoriesSettings, PlatformLoggerSettings } from "../interfaces";
@@ -39,20 +39,11 @@ export declare class PlatformConfiguration extends DIConfiguration {
39
39
  set logger(value: Partial<PlatformLoggerSettings>);
40
40
  get exclude(): string[];
41
41
  set exclude(exclude: string[]);
42
- /**
43
- *
44
- * @param addressPort
45
- * @returns {{address: string, port: number}}
46
- */
47
- private static buildAddressAndPort;
48
42
  /**
49
43
  *
50
44
  * @returns {string|number}
51
45
  */
52
- getHttpPort(): {
53
- address: string;
54
- port: number;
55
- };
46
+ getHttpPort(): ReturnType<typeof getHostInfoFromPort>;
56
47
  /**
57
48
  *
58
49
  * @param settings
@@ -66,8 +57,10 @@ export declare class PlatformConfiguration extends DIConfiguration {
66
57
  * @returns {string|number}
67
58
  */
68
59
  getHttpsPort(): {
60
+ protocol: string;
69
61
  address: string;
70
62
  port: number;
63
+ toString(): string;
71
64
  };
72
65
  /**
73
66
  *
@@ -78,8 +71,11 @@ export declare class PlatformConfiguration extends DIConfiguration {
78
71
  port: number;
79
72
  }): void;
80
73
  getBestHost(): {
74
+ protocol: string;
81
75
  address: string;
82
76
  port: number;
83
- protocol: string;
84
- } | undefined;
77
+ toString(): string;
78
+ } | {
79
+ toString(): string;
80
+ };
85
81
  }
@@ -22,6 +22,7 @@ import Http from "http";
22
22
  * @param {TypedPropertyDescriptor<Function> | number} descriptor
23
23
  * @returns {any}
24
24
  * @decorator
25
+ * @deprecated Use Https.Server from "http"
25
26
  */
26
27
  export declare function HttpServer(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any;
27
28
  export declare type HttpServer = Http.Server;
@@ -22,6 +22,7 @@ import Https from "https";
22
22
  * @param {TypedPropertyDescriptor<Function> | number} descriptor
23
23
  * @returns {any}
24
24
  * @decorator
25
+ * @deprecated Use Https.Server from "https"
25
26
  */
26
27
  export declare function HttpsServer(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any;
27
28
  export declare type HttpsServer = Https.Server;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { InjectorService } from "@tsed/di";
2
- export declare function createHttpServer(injector: InjectorService): void;
3
- export declare function listenHttpServer(injector: InjectorService): Promise<void>;
3
+ import Http from "http";
4
+ export declare function createHttpServer(injector: InjectorService, requestListener: Http.RequestListener): (() => Promise<void>) | undefined;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { InjectorService } from "@tsed/di";
2
- export declare function createHttpsServer(injector: InjectorService): void;
3
- export declare function listenHttpsServer(injector: InjectorService): Promise<void>;
3
+ import Http from "http";
4
+ export declare function createHttpsServer(injector: InjectorService, requestListener?: Http.RequestListener): (() => Promise<void>) | undefined;
@@ -1,10 +1,7 @@
1
1
  /// <reference types="node" />
2
- import Http from "http";
3
- import Https from "https";
4
- export declare function listenServer(http: Http.Server | Https.Server, settings: {
5
- address: string | number;
6
- port: number;
7
- }): Promise<{
8
- address: string;
9
- port: number;
10
- }>;
2
+ import type Http from "http";
3
+ import type Https from "https";
4
+ import type Http2 from "http2";
5
+ import { InjectorService } from "@tsed/di";
6
+ import { getHostInfoFromPort } from "@tsed/core";
7
+ export declare function listenServer(injector: InjectorService, server: Http.Server | Https.Server | Http2.Http2Server, hostInfo: ReturnType<typeof getHostInfoFromPort>): Promise<ReturnType<typeof getHostInfoFromPort>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/common",
3
- "version": "6.91.0",
3
+ "version": "6.92.0",
4
4
  "description": "A TypeScript Framework on top of Express",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -59,22 +59,22 @@
59
59
  }
60
60
  ],
61
61
  "dependencies": {
62
- "@tsed/components-scan": "6.91.0",
63
- "@tsed/core": "6.91.0",
64
- "@tsed/di": "6.91.0",
65
- "@tsed/exceptions": "6.91.0",
66
- "@tsed/json-mapper": "6.91.0",
62
+ "@tsed/components-scan": "6.92.0",
63
+ "@tsed/core": "6.92.0",
64
+ "@tsed/di": "6.92.0",
65
+ "@tsed/exceptions": "6.92.0",
66
+ "@tsed/json-mapper": "6.92.0",
67
67
  "@tsed/logger": "^6.0.0",
68
68
  "@tsed/logger-file": "^6.0.0",
69
- "@tsed/perf": "6.91.0",
70
- "@tsed/platform-cache": "6.91.0",
71
- "@tsed/platform-exceptions": "6.91.0",
72
- "@tsed/platform-log-middleware": "6.91.0",
73
- "@tsed/platform-middlewares": "6.91.0",
74
- "@tsed/platform-params": "6.91.0",
75
- "@tsed/platform-response-filter": "6.91.0",
76
- "@tsed/platform-views": "6.91.0",
77
- "@tsed/schema": "6.91.0",
69
+ "@tsed/perf": "6.92.0",
70
+ "@tsed/platform-cache": "6.92.0",
71
+ "@tsed/platform-exceptions": "6.92.0",
72
+ "@tsed/platform-log-middleware": "6.92.0",
73
+ "@tsed/platform-middlewares": "6.92.0",
74
+ "@tsed/platform-params": "6.92.0",
75
+ "@tsed/platform-response-filter": "6.92.0",
76
+ "@tsed/platform-views": "6.92.0",
77
+ "@tsed/schema": "6.92.0",
78
78
  "@types/json-schema": "7.0.7",
79
79
  "on-finished": "2.3.0",
80
80
  "tslib": "2.2.0",