@tsed/common 7.0.0-beta.12 → 7.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +14 -0
- package/lib/cjs/builder/PlatformBuilder.js +65 -55
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/builder/PlatformControllerBuilder.js +1 -1
- package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -1
- package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/cjs/config/services/PlatformConfiguration.js +0 -70
- package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
- package/lib/cjs/domain/AnyToPromiseWithCtx.js +4 -3
- package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/cjs/domain/ControllerProvider.js +1 -0
- package/lib/cjs/domain/ControllerProvider.js.map +1 -1
- package/lib/cjs/domain/HandlerMetadata.js +10 -5
- package/lib/cjs/domain/HandlerMetadata.js.map +1 -1
- package/lib/cjs/domain/PlatformContext.js +54 -31
- package/lib/cjs/domain/PlatformContext.js.map +1 -1
- package/lib/cjs/domain/PlatformRouteDetails.js +5 -1
- package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js +2 -0
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/cjs/services/FakeAdapter.js +1 -3
- package/lib/cjs/services/FakeAdapter.js.map +1 -1
- package/lib/cjs/services/Platform.js +4 -2
- package/lib/cjs/services/Platform.js.map +1 -1
- package/lib/cjs/services/PlatformAdapter.js +12 -0
- package/lib/cjs/services/PlatformAdapter.js.map +1 -1
- package/lib/cjs/services/PlatformApplication.js +2 -0
- package/lib/cjs/services/PlatformApplication.js.map +1 -1
- package/lib/cjs/services/PlatformHandler.js +7 -4
- package/lib/cjs/services/PlatformHandler.js.map +1 -1
- package/lib/cjs/services/PlatformMiddlewaresChain.js +3 -1
- package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/cjs/services/PlatformRequest.js +16 -11
- package/lib/cjs/services/PlatformRequest.js.map +1 -1
- package/lib/cjs/services/PlatformResponse.js +15 -11
- package/lib/cjs/services/PlatformResponse.js.map +1 -1
- package/lib/cjs/services/PlatformRouter.js +7 -1
- package/lib/cjs/services/PlatformRouter.js.map +1 -1
- package/lib/cjs/services/PlatformTest.js +20 -8
- package/lib/cjs/services/PlatformTest.js.map +1 -1
- package/lib/cjs/utils/createContext.js +28 -13
- package/lib/cjs/utils/createContext.js.map +1 -1
- package/lib/cjs/utils/createHttpServer.js +3 -3
- package/lib/cjs/utils/createHttpServer.js.map +1 -1
- package/lib/cjs/utils/createHttpsServer.js +3 -3
- package/lib/cjs/utils/createHttpsServer.js.map +1 -1
- package/lib/cjs/utils/createInjector.js +6 -6
- package/lib/cjs/utils/createInjector.js.map +1 -1
- package/lib/cjs/utils/getConfiguration.js +2 -12
- package/lib/cjs/utils/getConfiguration.js.map +1 -1
- package/lib/cjs/utils/setResponseHeaders.js +7 -13
- package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +42 -55
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/builder/PlatformControllerBuilder.js +1 -1
- package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -1
- package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/esm/config/services/PlatformConfiguration.js +0 -70
- package/lib/esm/config/services/PlatformConfiguration.js.map +1 -1
- package/lib/esm/domain/AnyToPromiseWithCtx.js +4 -3
- package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/esm/domain/ControllerProvider.js +1 -0
- package/lib/esm/domain/ControllerProvider.js.map +1 -1
- package/lib/esm/domain/HandlerMetadata.js +10 -5
- package/lib/esm/domain/HandlerMetadata.js.map +1 -1
- package/lib/esm/domain/PlatformContext.js +54 -31
- package/lib/esm/domain/PlatformContext.js.map +1 -1
- package/lib/esm/domain/PlatformRouteDetails.js +5 -1
- package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
- package/lib/esm/middlewares/PlatformMulterMiddleware.js +2 -0
- package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/esm/services/FakeAdapter.js +1 -3
- package/lib/esm/services/FakeAdapter.js.map +1 -1
- package/lib/esm/services/Platform.js +4 -2
- package/lib/esm/services/Platform.js.map +1 -1
- package/lib/esm/services/PlatformAdapter.js +12 -0
- package/lib/esm/services/PlatformAdapter.js.map +1 -1
- package/lib/esm/services/PlatformApplication.js +2 -0
- package/lib/esm/services/PlatformApplication.js.map +1 -1
- package/lib/esm/services/PlatformHandler.js +8 -5
- package/lib/esm/services/PlatformHandler.js.map +1 -1
- package/lib/esm/services/PlatformMiddlewaresChain.js +3 -1
- package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/esm/services/PlatformRequest.js +16 -11
- package/lib/esm/services/PlatformRequest.js.map +1 -1
- package/lib/esm/services/PlatformResponse.js +15 -11
- package/lib/esm/services/PlatformResponse.js.map +1 -1
- package/lib/esm/services/PlatformRouter.js +7 -1
- package/lib/esm/services/PlatformRouter.js.map +1 -1
- package/lib/esm/services/PlatformTest.js +20 -8
- package/lib/esm/services/PlatformTest.js.map +1 -1
- package/lib/esm/utils/createContext.js +26 -12
- package/lib/esm/utils/createContext.js.map +1 -1
- package/lib/esm/utils/createHttpServer.js +3 -3
- package/lib/esm/utils/createHttpServer.js.map +1 -1
- package/lib/esm/utils/createHttpsServer.js +3 -3
- package/lib/esm/utils/createHttpsServer.js.map +1 -1
- package/lib/esm/utils/createInjector.js +7 -7
- package/lib/esm/utils/createInjector.js.map +1 -1
- package/lib/esm/utils/getConfiguration.js +4 -14
- package/lib/esm/utils/getConfiguration.js.map +1 -1
- package/lib/esm/utils/setResponseHeaders.js +7 -13
- package/lib/esm/utils/setResponseHeaders.js.map +1 -1
- package/lib/types/builder/PlatformBuilder.d.ts +4 -5
- package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +2 -43
- package/lib/types/config/services/PlatformConfiguration.d.ts +1 -22
- package/lib/types/domain/PlatformContext.d.ts +20 -14
- package/lib/types/domain/PlatformRouteDetails.d.ts +1 -7
- package/lib/types/services/PlatformRequest.d.ts +11 -8
- package/lib/types/services/PlatformResponse.d.ts +8 -9
- package/lib/types/services/PlatformTest.d.ts +2 -2
- package/lib/types/utils/createContext.d.ts +4 -1
- package/lib/types/utils/createHttpsServer.d.ts +1 -0
- package/lib/types/utils/createInjector.d.ts +1 -1
- package/lib/types/utils/listenServer.d.ts +2 -0
- package/package.json +22 -21
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js +0 -12
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +0 -1
- package/lib/cjs/utils/__mock__/Test1.js +0 -8
- package/lib/cjs/utils/__mock__/Test1.js.map +0 -1
- package/lib/cjs/utils/__mock__/Test2.js +0 -8
- package/lib/cjs/utils/__mock__/Test2.js.map +0 -1
- package/lib/cjs/utils/__mock__/controllers/rest/TestCtrl.js +0 -12
- package/lib/cjs/utils/__mock__/controllers/rest/TestCtrl.js.map +0 -1
- package/lib/cjs/utils/__mock__/module1/Module1.js +0 -19
- package/lib/cjs/utils/__mock__/module1/Module1.js.map +0 -1
- package/lib/cjs/utils/__mock__/module1/controllers/M1Ctrl1.js +0 -17
- package/lib/cjs/utils/__mock__/module1/controllers/M1Ctrl1.js.map +0 -1
- package/lib/cjs/utils/__mock__/module1/services/M1Service.js +0 -17
- package/lib/cjs/utils/__mock__/module1/services/M1Service.js.map +0 -1
- package/lib/cjs/utils/__mock__/module1/submodule/SubModule.js +0 -15
- package/lib/cjs/utils/__mock__/module1/submodule/SubModule.js.map +0 -1
- package/lib/cjs/utils/__mock__/module1/submodule/SubService.js +0 -12
- package/lib/cjs/utils/__mock__/module1/submodule/SubService.js.map +0 -1
- package/lib/cjs/utils/__mock__/module2/Module2.js +0 -18
- package/lib/cjs/utils/__mock__/module2/Module2.js.map +0 -1
- package/lib/cjs/utils/__mock__/module2/controllers/M2Ctrl.js +0 -12
- package/lib/cjs/utils/__mock__/module2/controllers/M2Ctrl.js.map +0 -1
- package/lib/esm/middlewares/__mock__/FakeCtrl.js +0 -9
- package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +0 -1
- package/lib/esm/utils/__mock__/Test1.js +0 -4
- package/lib/esm/utils/__mock__/Test1.js.map +0 -1
- package/lib/esm/utils/__mock__/Test2.js +0 -4
- package/lib/esm/utils/__mock__/Test2.js.map +0 -1
- package/lib/esm/utils/__mock__/controllers/rest/TestCtrl.js +0 -9
- package/lib/esm/utils/__mock__/controllers/rest/TestCtrl.js.map +0 -1
- package/lib/esm/utils/__mock__/module1/Module1.js +0 -16
- package/lib/esm/utils/__mock__/module1/Module1.js.map +0 -1
- package/lib/esm/utils/__mock__/module1/controllers/M1Ctrl1.js +0 -14
- package/lib/esm/utils/__mock__/module1/controllers/M1Ctrl1.js.map +0 -1
- package/lib/esm/utils/__mock__/module1/services/M1Service.js +0 -14
- package/lib/esm/utils/__mock__/module1/services/M1Service.js.map +0 -1
- package/lib/esm/utils/__mock__/module1/submodule/SubModule.js +0 -12
- package/lib/esm/utils/__mock__/module1/submodule/SubModule.js.map +0 -1
- package/lib/esm/utils/__mock__/module1/submodule/SubService.js +0 -9
- package/lib/esm/utils/__mock__/module1/submodule/SubService.js.map +0 -1
- package/lib/esm/utils/__mock__/module2/Module2.js +0 -15
- package/lib/esm/utils/__mock__/module2/Module2.js.map +0 -1
- package/lib/esm/utils/__mock__/module2/controllers/M2Ctrl.js +0 -9
- package/lib/esm/utils/__mock__/module2/controllers/M2Ctrl.js.map +0 -1
- package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +0 -2
- package/lib/types/utils/__mock__/Test1.d.ts +0 -3
- package/lib/types/utils/__mock__/Test2.d.ts +0 -3
- package/lib/types/utils/__mock__/controllers/rest/TestCtrl.d.ts +0 -2
- package/lib/types/utils/__mock__/module1/Module1.d.ts +0 -2
- package/lib/types/utils/__mock__/module1/controllers/M1Ctrl1.d.ts +0 -5
- package/lib/types/utils/__mock__/module1/services/M1Service.d.ts +0 -5
- package/lib/types/utils/__mock__/module1/submodule/SubModule.d.ts +0 -2
- package/lib/types/utils/__mock__/module1/submodule/SubService.d.ts +0 -2
- package/lib/types/utils/__mock__/module2/Module2.d.ts +0 -2
- package/lib/types/utils/__mock__/module2/controllers/M2Ctrl.d.ts +0 -2
|
@@ -9,10 +9,8 @@ function getConfiguration(configuration = {}, module = null) {
|
|
|
9
9
|
}
|
|
10
10
|
const store = module ? core_1.Store.from(module).get("configuration") || {} : {};
|
|
11
11
|
const env = configuration.env || store.env || process.env.NODE_ENV || core_1.Env.DEV;
|
|
12
|
-
|
|
12
|
+
return {
|
|
13
13
|
$$resolved: true,
|
|
14
|
-
exclude: ["**/*.spec.ts", "**/*.spec.js"],
|
|
15
|
-
componentsScan: ["${rootDir}/mvc/**/*.ts", "${rootDir}/services/**/*.ts", "${rootDir}/middlewares/**/*.ts"],
|
|
16
14
|
env,
|
|
17
15
|
httpPort: 8080,
|
|
18
16
|
httpsPort: false,
|
|
@@ -23,11 +21,7 @@ function getConfiguration(configuration = {}, module = null) {
|
|
|
23
21
|
...store.scopes,
|
|
24
22
|
...configuration.scopes
|
|
25
23
|
},
|
|
26
|
-
mount: store.mount
|
|
27
|
-
? (0, core_1.deepMerge)(store.mount || {}, configuration.mount || {})
|
|
28
|
-
: {
|
|
29
|
-
"/rest": "${rootDir}/controllers/**/*.ts"
|
|
30
|
-
},
|
|
24
|
+
mount: (0, di_1.mergeMount)(store.mount, configuration.mount),
|
|
31
25
|
logger: {
|
|
32
26
|
debug: false,
|
|
33
27
|
level: env === core_1.Env.TEST ? "off" : "info",
|
|
@@ -37,10 +31,6 @@ function getConfiguration(configuration = {}, module = null) {
|
|
|
37
31
|
jsonIndentation: process.env.NODE_ENV === core_1.Env.PROD ? 0 : 2
|
|
38
32
|
}
|
|
39
33
|
};
|
|
40
|
-
if (!configuration.disableComponentsScan && store.componentsScan && configuration.componentsScan) {
|
|
41
|
-
config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];
|
|
42
|
-
}
|
|
43
|
-
return config;
|
|
44
34
|
}
|
|
45
35
|
exports.getConfiguration = getConfiguration;
|
|
46
36
|
//# sourceMappingURL=getConfiguration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getConfiguration.js","sourceRoot":"","sources":["../../../src/utils/getConfiguration.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"getConfiguration.js","sourceRoot":"","sources":["../../../src/utils/getConfiguration.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAC5C,iCAAiE;AAEjE,SAAgB,gBAAgB,CAAC,gBAAqB,EAAE,EAAE,SAA2B,IAAI;IACvF,IAAI,aAAa,CAAC,UAAU,EAAE;QAC5B,OAAO,aAAa,CAAC;KACtB;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1E,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,IAAK,OAAO,CAAC,GAAG,CAAC,QAAgB,IAAI,UAAG,CAAC,GAAG,CAAC;IAEvF,OAAO;QACL,UAAU,EAAE,IAAI;QAChB,GAAG;QACH,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,KAAK;QAChB,GAAG,KAAK;QACR,GAAG,aAAa;QAChB,MAAM,EAAE;YACN,CAAC,iBAAY,CAAC,UAAU,CAAC,EAAE,kBAAa,CAAC,SAAS;YAClD,GAAG,KAAK,CAAC,MAAM;YACf,GAAG,aAAa,CAAC,MAAM;SACxB;QACD,KAAK,EAAE,IAAA,eAAU,EAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC;QACnD,MAAM,EAAE;YACN,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,GAAG,KAAK,UAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM;YACxC,UAAU,EAAE,IAAI;YAChB,GAAG,KAAK,CAAC,MAAM;YACf,GAAG,aAAa,CAAC,MAAM;YACvB,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,UAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3D;KACF,CAAC;AACJ,CAAC;AA9BD,4CA8BC","sourcesContent":["import {Env, Store, Type} from \"@tsed/core\";\nimport {mergeMount, ProviderScope, ProviderType} from \"@tsed/di\";\n\nexport function getConfiguration(configuration: any = {}, module: Type<any> | null = null) {\n if (configuration.$$resolved) {\n return configuration;\n }\n\n const store = module ? Store.from(module).get(\"configuration\") || {} : {};\n const env = configuration.env || store.env || (process.env.NODE_ENV as Env) || Env.DEV;\n\n return {\n $$resolved: true,\n env,\n httpPort: 8080,\n httpsPort: false,\n ...store,\n ...configuration,\n scopes: {\n [ProviderType.CONTROLLER]: ProviderScope.SINGLETON,\n ...store.scopes,\n ...configuration.scopes\n },\n mount: mergeMount(store.mount, configuration.mount),\n logger: {\n debug: false,\n level: env === Env.TEST ? \"off\" : \"info\",\n logRequest: true,\n ...store.logger,\n ...configuration.logger,\n jsonIndentation: process.env.NODE_ENV === Env.PROD ? 0 : 2\n }\n };\n}\n"]}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setResponseHeaders = void 0;
|
|
4
|
-
function mergeHeaders(specHeaders, headers) {
|
|
5
|
-
return Object.entries(specHeaders).reduce((headers, [key, item]) => {
|
|
6
|
-
key = key.toLowerCase();
|
|
7
|
-
return {
|
|
8
|
-
...headers,
|
|
9
|
-
[key]: headers[key] === undefined ? String(item.example) : headers[key]
|
|
10
|
-
};
|
|
11
|
-
}, headers);
|
|
12
|
-
}
|
|
13
4
|
/**
|
|
14
5
|
* @ignore
|
|
15
6
|
*/
|
|
@@ -24,11 +15,14 @@ function setResponseHeaders(ctx) {
|
|
|
24
15
|
response.status(operation.getStatus());
|
|
25
16
|
}
|
|
26
17
|
const statusCode = response.statusCode;
|
|
27
|
-
const headers = operation.getHeadersOf(
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
const headers = operation.getHeadersOf(statusCode);
|
|
19
|
+
Object.entries(headers).forEach(([key, item]) => {
|
|
20
|
+
if (!response.get(key)) {
|
|
21
|
+
response.setHeader(key, String(item.example));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
30
24
|
if (operation.isRedirection(statusCode)) {
|
|
31
|
-
response.redirect(statusCode,
|
|
25
|
+
response.redirect(statusCode, response.get("location"));
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
28
|
exports.setResponseHeaders = setResponseHeaders;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setResponseHeaders.js","sourceRoot":"","sources":["../../../src/utils/setResponseHeaders.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"setResponseHeaders.js","sourceRoot":"","sources":["../../../src/utils/setResponseHeaders.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,SAAgB,kBAAkB,CAAC,GAAoB;IACrD,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAC,GAAG,GAAG,CAAC;IACjC,MAAM,EAAC,SAAS,EAAC,GAAG,QAAQ,CAAC;IAE7B,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE;QACrB,OAAO;KACR;IAED,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;QACzB,kDAAkD;QAClD,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;KACxC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACvC,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAEnD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;QAC9C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACtB,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;SAC/C;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE;QACvC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;KACzD;AACH,CAAC;AAzBD,gDAyBC","sourcesContent":["import {PlatformContext} from \"../domain/PlatformContext\";\n\n/**\n * @ignore\n */\nexport function setResponseHeaders(ctx: PlatformContext) {\n const {response, endpoint} = ctx;\n const {operation} = endpoint;\n\n if (response.isDone()) {\n return;\n }\n\n if (!response.hasStatus()) {\n // apply status only if the isn't already modified\n response.status(operation.getStatus());\n }\n\n const statusCode = response.statusCode;\n const headers = operation.getHeadersOf(statusCode);\n\n Object.entries(headers).forEach(([key, item]) => {\n if (!response.get(key)) {\n response.setHeader(key, String(item.example));\n }\n });\n\n if (operation.isRedirection(statusCode)) {\n response.redirect(statusCode, response.get(\"location\"));\n }\n}\n"]}
|
|
@@ -1,51 +1,50 @@
|
|
|
1
|
-
var _PlatformBuilder_injector, _PlatformBuilder_rootModule, _PlatformBuilder_adapter, _PlatformBuilder_promise, _PlatformBuilder_servers, _PlatformBuilder_listeners;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { nameOf } from "@tsed/core";
|
|
4
|
-
import { colors,
|
|
2
|
+
import { colors, setLoggerConfiguration } from "@tsed/di";
|
|
5
3
|
import { getMiddlewaresForHook } from "@tsed/platform-middlewares";
|
|
6
4
|
import { Platform } from "../services/Platform.js";
|
|
7
|
-
import { PlatformApplication } from "../services/PlatformApplication.js";
|
|
8
|
-
import { getStaticsOptions } from "../utils/getStaticsOptions.js";
|
|
9
|
-
import { getConfiguration } from "../utils/getConfiguration.js";
|
|
10
5
|
import { PlatformAdapter } from "../services/PlatformAdapter.js";
|
|
11
|
-
import {
|
|
12
|
-
import { printRoutes } from "../utils/printRoutes.js";
|
|
6
|
+
import { PlatformApplication } from "../services/PlatformApplication.js";
|
|
13
7
|
import { createHttpServer } from "../utils/createHttpServer.js";
|
|
14
8
|
import { createHttpsServer } from "../utils/createHttpsServer.js";
|
|
9
|
+
import { createInjector } from "../utils/createInjector.js";
|
|
10
|
+
import { getConfiguration } from "../utils/getConfiguration.js";
|
|
11
|
+
import { getStaticsOptions } from "../utils/getStaticsOptions.js";
|
|
12
|
+
import { printRoutes } from "../utils/printRoutes.js";
|
|
15
13
|
/**
|
|
16
14
|
* @platform
|
|
17
15
|
*/
|
|
18
16
|
export class PlatformBuilder {
|
|
17
|
+
static adapter;
|
|
18
|
+
name = "";
|
|
19
|
+
startedAt = new Date();
|
|
20
|
+
current = new Date();
|
|
21
|
+
#injector;
|
|
22
|
+
#rootModule;
|
|
23
|
+
#adapter;
|
|
24
|
+
#promise;
|
|
25
|
+
#servers;
|
|
26
|
+
#listeners = [];
|
|
19
27
|
constructor(adapter, module, settings) {
|
|
20
|
-
this
|
|
21
|
-
this.startedAt = new Date();
|
|
22
|
-
this.current = new Date();
|
|
23
|
-
_PlatformBuilder_injector.set(this, void 0);
|
|
24
|
-
_PlatformBuilder_rootModule.set(this, void 0);
|
|
25
|
-
_PlatformBuilder_adapter.set(this, void 0);
|
|
26
|
-
_PlatformBuilder_promise.set(this, void 0);
|
|
27
|
-
_PlatformBuilder_servers.set(this, void 0);
|
|
28
|
-
_PlatformBuilder_listeners.set(this, []);
|
|
29
|
-
__classPrivateFieldSet(this, _PlatformBuilder_rootModule, module, "f");
|
|
28
|
+
this.#rootModule = module;
|
|
30
29
|
const configuration = getConfiguration(settings, module);
|
|
31
30
|
const adapterKlass = adapter || PlatformBuilder.adapter;
|
|
32
31
|
const name = nameOf(adapterKlass).replace("Platform", "").toLowerCase();
|
|
33
32
|
configuration.PLATFORM_NAME = name;
|
|
34
33
|
this.name = name;
|
|
35
|
-
|
|
34
|
+
this.#injector = createInjector({
|
|
36
35
|
adapter: adapterKlass,
|
|
37
36
|
settings: configuration
|
|
38
|
-
})
|
|
39
|
-
|
|
37
|
+
});
|
|
38
|
+
this.#adapter = this.#injector.get(PlatformAdapter);
|
|
40
39
|
this.createHttpServers();
|
|
41
|
-
|
|
40
|
+
this.#adapter.onInit && this.#adapter.onInit();
|
|
42
41
|
this.log("Injector created...");
|
|
43
42
|
}
|
|
44
43
|
get injector() {
|
|
45
|
-
return
|
|
44
|
+
return this.#injector;
|
|
46
45
|
}
|
|
47
46
|
get rootModule() {
|
|
48
|
-
return
|
|
47
|
+
return this.#injector.get(this.#rootModule);
|
|
49
48
|
}
|
|
50
49
|
get app() {
|
|
51
50
|
return this.injector.get(PlatformApplication);
|
|
@@ -54,7 +53,7 @@ export class PlatformBuilder {
|
|
|
54
53
|
return this.injector.get(Platform);
|
|
55
54
|
}
|
|
56
55
|
get adapter() {
|
|
57
|
-
return
|
|
56
|
+
return this.#adapter;
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
60
59
|
* Return the settings configured by the decorator @@Configuration@@.
|
|
@@ -84,15 +83,13 @@ export class PlatformBuilder {
|
|
|
84
83
|
return this.injector.logger;
|
|
85
84
|
}
|
|
86
85
|
get disableBootstrapLog() {
|
|
87
|
-
|
|
88
|
-
return (_a = this.settings.logger) === null || _a === void 0 ? void 0 : _a.disableBootstrapLog;
|
|
86
|
+
return this.settings.get("logger.disableBootstrapLog");
|
|
89
87
|
}
|
|
90
88
|
static create(module, settings) {
|
|
91
89
|
return this.build(module, {
|
|
92
90
|
httpsPort: false,
|
|
93
91
|
httpPort: false,
|
|
94
|
-
...settings
|
|
95
|
-
disableComponentsScan: true
|
|
92
|
+
...settings
|
|
96
93
|
});
|
|
97
94
|
}
|
|
98
95
|
static build(module, { adapter, ...settings }) {
|
|
@@ -104,13 +101,7 @@ export class PlatformBuilder {
|
|
|
104
101
|
* @param settings
|
|
105
102
|
*/
|
|
106
103
|
static async bootstrap(module, settings) {
|
|
107
|
-
|
|
108
|
-
const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;
|
|
109
|
-
if (!disableComponentsScan) {
|
|
110
|
-
const { importProviders } = await import("@tsed/components-scan");
|
|
111
|
-
await importProviders(configuration);
|
|
112
|
-
}
|
|
113
|
-
return this.build(module, configuration).bootstrap();
|
|
104
|
+
return this.build(module, settings).bootstrap();
|
|
114
105
|
}
|
|
115
106
|
callback(req, res) {
|
|
116
107
|
if (req && res) {
|
|
@@ -124,10 +115,9 @@ export class PlatformBuilder {
|
|
|
124
115
|
/**
|
|
125
116
|
* Add classes to the components list
|
|
126
117
|
* @param classes
|
|
127
|
-
* @deprecated
|
|
128
118
|
*/
|
|
129
119
|
addComponents(classes) {
|
|
130
|
-
this.settings.
|
|
120
|
+
this.settings.set("imports", this.settings.get("imports", []).concat(classes));
|
|
131
121
|
return this;
|
|
132
122
|
}
|
|
133
123
|
/**
|
|
@@ -156,10 +146,10 @@ export class PlatformBuilder {
|
|
|
156
146
|
});
|
|
157
147
|
}
|
|
158
148
|
async runLifecycle() {
|
|
159
|
-
|
|
149
|
+
setLoggerConfiguration(this.injector);
|
|
160
150
|
await this.loadInjector();
|
|
161
|
-
|
|
162
|
-
|
|
151
|
+
this.#adapter.useContext && this.#adapter.useContext();
|
|
152
|
+
this.#adapter.useRouter && this.#adapter.useRouter();
|
|
163
153
|
await this.loadRoutes();
|
|
164
154
|
await this.logRoutes();
|
|
165
155
|
return this;
|
|
@@ -167,12 +157,12 @@ export class PlatformBuilder {
|
|
|
167
157
|
async loadInjector() {
|
|
168
158
|
const { injector } = this;
|
|
169
159
|
this.log("Build providers");
|
|
170
|
-
await injector.loadModule(
|
|
160
|
+
await injector.loadModule(this.#rootModule);
|
|
171
161
|
this.log("Settings and injector loaded...");
|
|
172
162
|
await this.callHook("$afterInit");
|
|
173
163
|
}
|
|
174
164
|
async listen(network = true) {
|
|
175
|
-
if (!
|
|
165
|
+
if (!this.#promise) {
|
|
176
166
|
await this.bootstrap();
|
|
177
167
|
}
|
|
178
168
|
await this.callHook("$beforeListen");
|
|
@@ -185,7 +175,7 @@ export class PlatformBuilder {
|
|
|
185
175
|
async stop() {
|
|
186
176
|
await this.callHook("$onDestroy");
|
|
187
177
|
await this.injector.destroy();
|
|
188
|
-
|
|
178
|
+
this.#listeners.map((server) => {
|
|
189
179
|
return new Promise((resolve) => server.close(() => resolve(undefined)));
|
|
190
180
|
});
|
|
191
181
|
}
|
|
@@ -218,14 +208,13 @@ export class PlatformBuilder {
|
|
|
218
208
|
return this;
|
|
219
209
|
}
|
|
220
210
|
async bootstrap() {
|
|
221
|
-
|
|
222
|
-
return
|
|
211
|
+
this.#promise = this.#promise || this.runLifecycle();
|
|
212
|
+
return this.#promise;
|
|
223
213
|
}
|
|
224
214
|
async loadRoutes() {
|
|
225
|
-
|
|
226
|
-
__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes && (await __classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes());
|
|
215
|
+
this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());
|
|
227
216
|
// istanbul ignore next
|
|
228
|
-
if (
|
|
217
|
+
if (this.settings.get("logger.level") !== "off") {
|
|
229
218
|
const { PlatformLogMiddleware } = await import("@tsed/platform-log-middleware");
|
|
230
219
|
this.app.use(PlatformLogMiddleware);
|
|
231
220
|
}
|
|
@@ -241,7 +230,7 @@ export class PlatformBuilder {
|
|
|
241
230
|
await this.callHook("$onRoutesInit");
|
|
242
231
|
await this.loadStatics("$afterRoutesInit");
|
|
243
232
|
await this.callHook("$afterRoutesInit");
|
|
244
|
-
|
|
233
|
+
this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());
|
|
245
234
|
}
|
|
246
235
|
diff() {
|
|
247
236
|
const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);
|
|
@@ -259,19 +248,17 @@ export class PlatformBuilder {
|
|
|
259
248
|
});
|
|
260
249
|
}
|
|
261
250
|
createHttpServers() {
|
|
262
|
-
|
|
251
|
+
this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(Boolean);
|
|
263
252
|
}
|
|
264
253
|
async listenServers() {
|
|
265
|
-
|
|
254
|
+
this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));
|
|
266
255
|
}
|
|
267
256
|
async logRoutes() {
|
|
268
|
-
var _a;
|
|
269
257
|
const { logger, platform } = this;
|
|
270
258
|
this.log("Routes mounted...");
|
|
271
|
-
if (!
|
|
259
|
+
if (!this.settings.get("logger.disableRoutesSummary") && !this.disableBootstrapLog) {
|
|
272
260
|
logger.info(printRoutes(await this.injector.alterAsync("$logRoutes", platform.getRoutes())));
|
|
273
261
|
}
|
|
274
262
|
}
|
|
275
263
|
}
|
|
276
|
-
_PlatformBuilder_injector = new WeakMap(), _PlatformBuilder_rootModule = new WeakMap(), _PlatformBuilder_adapter = new WeakMap(), _PlatformBuilder_promise = new WeakMap(), _PlatformBuilder_servers = new WeakMap(), _PlatformBuilder_listeners = new WeakMap();
|
|
277
264
|
//# sourceMappingURL=PlatformBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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f, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, setLoggerLevel, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {Route} from \"../interfaces/Route\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {printRoutes} from \"../utils/printRoutes\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport type Https from \"https\";\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.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.app.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.componentsScan = this.settings.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 setLoggerLevel(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.logger?.level !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\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.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,MAAM,EAAO,MAAM,YAAY,CAAC;AACxC,OAAO,EAAC,MAAM,EAAiC,sBAAsB,EAAgB,MAAM,UAAU,CAAC;AACtG,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAKjE,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,CA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CACF","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, 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 {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 });\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 return this.build<App, Router>(module, settings).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.app.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 */\n public addComponents(classes: Type | Type[]) {\n this.settings.set(\"imports\", this.settings.get<any[]>(\"imports\", []).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 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"]}
|
|
@@ -51,7 +51,7 @@ export function buildRouter(injector, provider, parentUseBefore = []) {
|
|
|
51
51
|
const platformMiddlewaresChain = injector.get(PlatformMiddlewaresChain);
|
|
52
52
|
// build all endpoints and his middlewares
|
|
53
53
|
getOperationsRoutes(provider.token).forEach((operationRoute) => {
|
|
54
|
-
const handlers = platformMiddlewaresChain
|
|
54
|
+
const handlers = platformMiddlewaresChain?.get(provider, operationRoute, parentUseBefore);
|
|
55
55
|
router.addRoute({
|
|
56
56
|
handlers,
|
|
57
57
|
token: operationRoute.token,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformControllerBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformControllerBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAmB,YAAY,EAAC,MAAM,UAAU,CAAC;AACxE,OAAO,EAAC,mBAAmB,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,wBAAwB,EAAC,MAAM,sCAAsC,CAAC;AAE9E,eAAe,CAAC,cAAc,CAAC,YAAY,CAAC,UAAU,EAAE,kBAAkB,EAAE;IAC1E,QAAQ,CAAC,QAA4B,EAAE,MAAW,EAAE,EAAC,QAAQ,EAAC;QAC5D,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;CACF,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AAC,CAAC;QAEH,MAAM,WAAW,GAAU,CAAC,GAAG,eAAe,EAAE,GAAG,SAAS,CAAC,CAAC;QAC9D,6BAA6B;QAC7B,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAgB,EAAE,EAAE;YACpC,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAuB,CAAC;YAExE,0BAA0B;YAC1B,IAAI,CAAC,aAAa,EAAE;gBAClB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;aAC7E;YAED,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {GlobalProviders, InjectorService, ProviderType} from \"@tsed/di\";\nimport {getOperationsRoutes, OperationMethods} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {PlatformRouter} from \"../services/PlatformRouter\";\nimport {PlatformMiddlewaresChain} from \"../services/PlatformMiddlewaresChain\";\n\nGlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {\n onInvoke(provider: ControllerProvider, locals: any, {injector}) {\n const router = createRouter(injector, provider);\n locals.set(PlatformRouter, router);\n }\n});\n\n/**\n * @ignore\n */\nfunction formatMethod(method: string | undefined) {\n return (method === OperationMethods.CUSTOM ? \"use\" : method || \"use\").toLowerCase();\n}\n\n/**\n * @ignore\n */\nexport function getRouter(injector: InjectorService, provider: ControllerProvider) {\n return injector.get(provider.tokenRouter)!;\n}\n\n/**\n * @ignore\n */\nexport function createRouter(injector: InjectorService, provider: ControllerProvider): PlatformRouter {\n const token = provider.tokenRouter;\n\n if (injector.has(token)) {\n return getRouter(injector, provider);\n }\n\n const router = PlatformRouter.create(injector, provider.routerOptions);\n\n return injector\n .add(token, {\n useValue: router\n })\n .invoke<PlatformRouter>(token);\n}\n\n/**\n * @ignore\n * @param injector\n * @param provider\n * @param parentUseBefore\n */\nexport function buildRouter(injector: InjectorService, provider: ControllerProvider, parentUseBefore: any[] = []) {\n const {\n middlewares: {useBefore},\n children\n } = provider;\n\n // Controller lifecycle\n const router = createRouter(injector, provider);\n\n if (!router.isBuilt) {\n router.isBuilt = true;\n\n const platformMiddlewaresChain = injector.get<PlatformMiddlewaresChain>(PlatformMiddlewaresChain);\n\n // build all endpoints and his middlewares\n getOperationsRoutes(provider.token).forEach((operationRoute) => {\n const handlers = platformMiddlewaresChain?.get(provider, operationRoute, parentUseBefore);\n\n router.addRoute({\n handlers,\n token: operationRoute.token,\n method: formatMethod(operationRoute.method),\n path: operationRoute.path,\n isFinal: operationRoute.isFinal\n });\n });\n\n const middlewares: any[] = [...parentUseBefore, ...useBefore];\n // build children controllers\n children.forEach((child: Type<any>) => {\n const childProvider = injector.getProvider(child) as ControllerProvider;\n\n /* istanbul ignore next */\n if (!childProvider) {\n throw new Error(\"Controller component not found in the ControllerRegistry\");\n }\n\n router.use(childProvider.path, buildRouter(injector, childProvider, middlewares));\n });\n }\n\n return router;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformLoggerSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformLoggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"PlatformLoggerSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformLoggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {DILoggerOptions} from \"@tsed/di\";\n\nexport interface PlatformLoggerSettings extends DILoggerOptions {}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { getHostInfoFromPort } from "@tsed/core";
|
|
3
3
|
import { DIConfiguration, Injectable, ProviderScope } from "@tsed/di";
|
|
4
|
-
import { $log } from "@tsed/logger";
|
|
5
4
|
const rootDir = process.cwd();
|
|
6
5
|
/**
|
|
7
6
|
* `PlatformConfiguration` contains all information about your Server configuration.
|
|
@@ -10,18 +9,6 @@ let PlatformConfiguration = class PlatformConfiguration extends DIConfiguration
|
|
|
10
9
|
constructor() {
|
|
11
10
|
super({ rootDir });
|
|
12
11
|
}
|
|
13
|
-
get version() {
|
|
14
|
-
return this.getRaw("version");
|
|
15
|
-
}
|
|
16
|
-
set version(v) {
|
|
17
|
-
this.setRaw("version", v);
|
|
18
|
-
}
|
|
19
|
-
get rootDir() {
|
|
20
|
-
return this.getRaw("rootDir");
|
|
21
|
-
}
|
|
22
|
-
set rootDir(value) {
|
|
23
|
-
this.setRaw("rootDir", value);
|
|
24
|
-
}
|
|
25
12
|
get port() {
|
|
26
13
|
return this.httpPort;
|
|
27
14
|
}
|
|
@@ -46,30 +33,12 @@ let PlatformConfiguration = class PlatformConfiguration extends DIConfiguration
|
|
|
46
33
|
set httpsPort(value) {
|
|
47
34
|
this.setRaw("httpsPort", value);
|
|
48
35
|
}
|
|
49
|
-
get env() {
|
|
50
|
-
return this.getRaw("env");
|
|
51
|
-
}
|
|
52
|
-
set env(value) {
|
|
53
|
-
this.setRaw("env", value);
|
|
54
|
-
}
|
|
55
36
|
get mount() {
|
|
56
37
|
return this.get("mount");
|
|
57
38
|
}
|
|
58
39
|
set mount(value) {
|
|
59
40
|
this.setRaw("mount", value);
|
|
60
41
|
}
|
|
61
|
-
/**
|
|
62
|
-
* @deprecated
|
|
63
|
-
*/
|
|
64
|
-
get componentsScan() {
|
|
65
|
-
return this.resolve(this.getRaw("componentsScan"));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @deprecated
|
|
69
|
-
*/
|
|
70
|
-
set componentsScan(value) {
|
|
71
|
-
this.setRaw("componentsScan", value);
|
|
72
|
-
}
|
|
73
42
|
get statics() {
|
|
74
43
|
return this.getRaw("statics") || this.getRaw("serveStatic") || {};
|
|
75
44
|
}
|
|
@@ -82,51 +51,12 @@ let PlatformConfiguration = class PlatformConfiguration extends DIConfiguration
|
|
|
82
51
|
set acceptMimes(value) {
|
|
83
52
|
this.setRaw("acceptMimes", value || []);
|
|
84
53
|
}
|
|
85
|
-
get debug() {
|
|
86
|
-
return this.logger.level === "debug";
|
|
87
|
-
}
|
|
88
|
-
set debug(debug) {
|
|
89
|
-
this.logger = { ...this.logger, level: debug ? "debug" : "info" };
|
|
90
|
-
}
|
|
91
54
|
get converter() {
|
|
92
55
|
return this.get("converter") || {};
|
|
93
56
|
}
|
|
94
57
|
set converter(options) {
|
|
95
58
|
this.setRaw("converter", options);
|
|
96
59
|
}
|
|
97
|
-
get logger() {
|
|
98
|
-
return this.get("logger");
|
|
99
|
-
}
|
|
100
|
-
set logger(value) {
|
|
101
|
-
const logger = { ...this.logger, ...value };
|
|
102
|
-
logger.debug = logger.level === "debug";
|
|
103
|
-
this.setRaw("logger", logger);
|
|
104
|
-
this.setRaw("debug", logger.debug);
|
|
105
|
-
if (logger.format) {
|
|
106
|
-
$log.appenders.set("stdout", {
|
|
107
|
-
type: "stdout",
|
|
108
|
-
levels: ["info", "debug"],
|
|
109
|
-
layout: {
|
|
110
|
-
type: "pattern",
|
|
111
|
-
pattern: logger.format
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
$log.appenders.set("stderr", {
|
|
115
|
-
levels: ["trace", "fatal", "error", "warn"],
|
|
116
|
-
type: "stderr",
|
|
117
|
-
layout: {
|
|
118
|
-
type: "pattern",
|
|
119
|
-
pattern: logger.format
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
get exclude() {
|
|
125
|
-
return this.get("exclude");
|
|
126
|
-
}
|
|
127
|
-
set exclude(exclude) {
|
|
128
|
-
this.setRaw("exclude", exclude);
|
|
129
|
-
}
|
|
130
60
|
get additionalProperties() {
|
|
131
61
|
return this.get("converter.additionalProperties") === "accept";
|
|
132
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformConfiguration.js","sourceRoot":"","sources":["../../../../src/config/services/PlatformConfiguration.ts"],"names":[],"mappings":";AAAA,OAAO,EAAM,mBAAmB,EAAC,MAAM,YAAY,CAAC;AACpD,OAAO,EAAC,eAAe,EAAE,UAAU,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"PlatformConfiguration.js","sourceRoot":"","sources":["../../../../src/config/services/PlatformConfiguration.ts"],"names":[],"mappings":";AAAA,OAAO,EAAM,mBAAmB,EAAC,MAAM,YAAY,CAAC;AACpD,OAAO,EAAC,eAAe,EAAE,UAAU,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;AAInF,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAE9B;;GAEG;AAKH,IAAa,qBAAqB,GAAlC,MAAa,qBAAsB,SAAQ,eAAe;IACxD;QACE,KAAK,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,IAAI,CAAC,KAA8B;QACrC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,YAAY,CAAC,KAA0B;QACzC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,QAAQ,CAAC,KAA8B;QACzC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC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U,EAAE,GAAG,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,OAAO,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,QAAyC;QACpD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,WAAW;QACT,MAAM,EAAC,SAAS,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC;QAEnC,IAAI,SAAS,EAAE;YACb,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;SAC5B;QAED,IAAI,QAAQ,EAAE;YACZ,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;SAC3B;QAED,OAAO;YACL,QAAQ;gBACN,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA1HY,qBAAqB;IAJjC,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,MAAM,EAAE,IAAI;KACb,CAAC;;GACW,qBAAqB,CA0HjC;SA1HY,qBAAqB","sourcesContent":["import {Env, getHostInfoFromPort} from \"@tsed/core\";\nimport {DIConfiguration, Injectable, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport Https from \"https\";\nimport {ConverterSettings} from \"../interfaces/ConverterSettings\";\n\nconst rootDir = process.cwd();\n\n/**\n * `PlatformConfiguration` contains all information about your Server configuration.\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n global: true\n})\nexport class PlatformConfiguration extends DIConfiguration {\n constructor() {\n super({rootDir});\n }\n\n get port(): string | number | false {\n return this.httpPort;\n }\n\n set port(value: string | number | false) {\n this.httpPort = value;\n }\n\n get httpsOptions(): Https.ServerOptions {\n return this.getRaw(\"httpsOptions\");\n }\n\n set httpsOptions(value: Https.ServerOptions) {\n this.setRaw(\"httpsOptions\", value);\n }\n\n get httpPort(): string | number | false {\n return this.getRaw(\"httpPort\");\n }\n\n set httpPort(value: string | number | false) {\n this.setRaw(\"httpPort\", value);\n }\n\n get httpsPort(): string | number | false {\n return this.getRaw(\"httpsPort\");\n }\n\n set httpsPort(value: string | number | false) {\n this.setRaw(\"httpsPort\", value);\n }\n\n get mount(): Record<string, TokenProvider[]> {\n return this.get(\"mount\");\n }\n\n set mount(value: Record<string, TokenProvider[]>) {\n this.setRaw(\"mount\", value);\n }\n\n get statics(): Record<string, (any | string)[]> {\n return this.getRaw(\"statics\") || this.getRaw(\"serveStatic\") || {};\n }\n\n set statics(value: Record<string, (any | string)[]>) {\n this.setRaw(\"statics\", value);\n }\n\n get acceptMimes(): string[] {\n return this.getRaw(\"acceptMimes\");\n }\n\n set acceptMimes(value: string[]) {\n this.setRaw(\"acceptMimes\", value || []);\n }\n\n get converter(): Partial<ConverterSettings> {\n return this.get(\"converter\") || {};\n }\n\n set converter(options: Partial<ConverterSettings>) {\n this.setRaw(\"converter\", options);\n }\n\n get additionalProperties() {\n return this.get(\"converter.additionalProperties\") === \"accept\";\n }\n\n /**\n *\n * @returns {string|number}\n */\n getHttpPort(): ReturnType<typeof getHostInfoFromPort> {\n return getHostInfoFromPort(\"http\", this.getRaw(\"httpPort\"));\n }\n\n /**\n *\n * @param settings\n */\n setHttpPort(settings: {address: string; port: number}) {\n this.setRaw(\"httpPort\", `${settings.address}:${settings.port}`);\n }\n\n /**\n *\n * @returns {string|number}\n */\n getHttpsPort() {\n return getHostInfoFromPort(\"https\", this.getRaw(\"httpsPort\"));\n }\n\n /**\n *\n * @param settings\n */\n setHttpsPort(settings: {address: string; port: number}) {\n this.setRaw(\"httpsPort\", `${settings.address}:${settings.port}`);\n }\n\n getBestHost() {\n const {httpsPort, httpPort} = this;\n\n if (httpsPort) {\n return this.getHttpsPort();\n }\n\n if (httpPort) {\n return this.getHttpPort();\n }\n\n return {\n toString() {\n return \"/\";\n }\n };\n }\n}\n"]}
|