@tsed/common 7.0.0-beta.7 → 7.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage.json +6 -0
- package/jest.config.js +9 -0
- package/lib/cjs/builder/PlatformBuilder.js +86 -68
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/cjs/config/services/PlatformConfiguration.js +0 -64
- package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
- package/lib/cjs/decorators/params/error.js +1 -1
- package/lib/cjs/decorators/params/error.js.map +1 -1
- package/lib/cjs/domain/AnyToPromiseWithCtx.js +4 -5
- package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/cjs/domain/PlatformContext.js +46 -38
- package/lib/cjs/domain/PlatformContext.js.map +1 -1
- package/lib/cjs/domain/PlatformRouteDetails.js +0 -21
- package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/cjs/exports.js +1 -0
- package/lib/cjs/exports.js.map +1 -1
- package/lib/cjs/index.js +1 -9
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -1
- package/lib/cjs/interfaces/Route.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 +6 -12
- package/lib/cjs/services/FakeAdapter.js.map +1 -1
- package/lib/cjs/services/Platform.js +30 -86
- package/lib/cjs/services/Platform.js.map +1 -1
- package/lib/cjs/services/PlatformAdapter.js +10 -0
- package/lib/cjs/services/PlatformAdapter.js.map +1 -1
- package/lib/cjs/services/PlatformApplication.js +23 -9
- package/lib/cjs/services/PlatformApplication.js.map +1 -1
- package/lib/cjs/services/PlatformHandler.js +112 -171
- package/lib/cjs/services/PlatformHandler.js.map +1 -1
- package/lib/cjs/services/PlatformMiddlewaresChain.js +5 -19
- package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/cjs/services/PlatformRequest.js +16 -12
- package/lib/cjs/services/PlatformRequest.js.map +1 -1
- package/lib/cjs/services/PlatformResponse.js +19 -22
- package/lib/cjs/services/PlatformResponse.js.map +1 -1
- package/lib/cjs/services/PlatformTest.js +29 -9
- package/lib/cjs/services/PlatformTest.js.map +1 -1
- package/lib/cjs/utils/createContext.js +32 -21
- 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 -8
- package/lib/cjs/utils/createInjector.js.map +1 -1
- package/lib/cjs/utils/ensureContext.js +16 -0
- package/lib/cjs/utils/ensureContext.js.map +1 -0
- package/lib/cjs/utils/getConfiguration.js +6 -12
- package/lib/cjs/utils/getConfiguration.js.map +1 -1
- package/lib/cjs/utils/printRoutes.js +10 -8
- package/lib/cjs/utils/printRoutes.js.map +1 -1
- package/lib/cjs/utils/setResponseHeaders.js +8 -14
- package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +63 -68
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/esm/config/services/PlatformConfiguration.js +0 -64
- package/lib/esm/config/services/PlatformConfiguration.js.map +1 -1
- package/lib/esm/decorators/params/error.js +1 -1
- package/lib/esm/decorators/params/error.js.map +1 -1
- package/lib/esm/domain/AnyToPromiseWithCtx.js +4 -5
- package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/esm/domain/PlatformContext.js +46 -38
- package/lib/esm/domain/PlatformContext.js.map +1 -1
- package/lib/esm/domain/PlatformRouteDetails.js +1 -19
- package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/esm/exports.js +1 -0
- package/lib/esm/exports.js.map +1 -1
- package/lib/esm/index.js +1 -9
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -1
- package/lib/esm/interfaces/Route.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 +6 -12
- package/lib/esm/services/FakeAdapter.js.map +1 -1
- package/lib/esm/services/Platform.js +31 -87
- package/lib/esm/services/Platform.js.map +1 -1
- package/lib/esm/services/PlatformAdapter.js +10 -0
- package/lib/esm/services/PlatformAdapter.js.map +1 -1
- package/lib/esm/services/PlatformApplication.js +23 -9
- package/lib/esm/services/PlatformApplication.js.map +1 -1
- package/lib/esm/services/PlatformHandler.js +114 -173
- package/lib/esm/services/PlatformHandler.js.map +1 -1
- package/lib/esm/services/PlatformMiddlewaresChain.js +5 -19
- package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/esm/services/PlatformRequest.js +16 -12
- package/lib/esm/services/PlatformRequest.js.map +1 -1
- package/lib/esm/services/PlatformResponse.js +19 -22
- package/lib/esm/services/PlatformResponse.js.map +1 -1
- package/lib/esm/services/PlatformTest.js +29 -9
- package/lib/esm/services/PlatformTest.js.map +1 -1
- package/lib/esm/utils/createContext.js +30 -20
- 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 -9
- package/lib/esm/utils/createInjector.js.map +1 -1
- package/lib/esm/utils/ensureContext.js +12 -0
- package/lib/esm/utils/ensureContext.js.map +1 -0
- package/lib/esm/utils/getConfiguration.js +8 -14
- package/lib/esm/utils/getConfiguration.js.map +1 -1
- package/lib/esm/utils/printRoutes.js +10 -8
- package/lib/esm/utils/printRoutes.js.map +1 -1
- package/lib/esm/utils/setResponseHeaders.js +8 -14
- package/lib/esm/utils/setResponseHeaders.js.map +1 -1
- package/lib/types/builder/PlatformBuilder.d.ts +17 -16
- package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +2 -43
- package/lib/types/config/services/PlatformConfiguration.d.ts +6 -22
- package/lib/types/domain/AnyToPromiseWithCtx.d.ts +1 -9
- package/lib/types/domain/PlatformContext.d.ts +32 -18
- package/lib/types/domain/PlatformRouteDetails.d.ts +4 -19
- package/lib/types/exports.d.ts +1 -0
- package/lib/types/index.d.ts +1 -9
- package/lib/types/interfaces/PlatformRouteOptions.d.ts +0 -1
- package/lib/types/interfaces/Route.d.ts +2 -3
- package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +1 -1
- package/lib/types/services/FakeAdapter.d.ts +7 -6
- package/lib/types/services/Platform.d.ts +7 -28
- package/lib/types/services/PlatformAdapter.d.ts +22 -11
- package/lib/types/services/PlatformApplication.d.ts +14 -6
- package/lib/types/services/PlatformHandler.d.ts +21 -59
- package/lib/types/services/PlatformMiddlewaresChain.d.ts +1 -2
- package/lib/types/services/PlatformRequest.d.ts +8 -10
- package/lib/types/services/PlatformResponse.d.ts +11 -15
- package/lib/types/services/PlatformTest.d.ts +4 -3
- 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 +2 -2
- package/lib/types/utils/ensureContext.d.ts +2 -0
- package/lib/types/utils/listenServer.d.ts +2 -0
- package/package.json +28 -23
- package/readme.md +2 -1
- package/lib/cjs/builder/PlatformControllerBuilder.js +0 -82
- package/lib/cjs/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js +0 -3
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js.map +0 -1
- package/lib/cjs/domain/ControllerProvider.js +0 -51
- package/lib/cjs/domain/ControllerProvider.js.map +0 -1
- package/lib/cjs/domain/HandlerMetadata.js +0 -57
- package/lib/cjs/domain/HandlerMetadata.js.map +0 -1
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js +0 -12
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +0 -1
- package/lib/cjs/middlewares/bindEndpointMiddleware.js +0 -13
- package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +0 -1
- package/lib/cjs/services/PlatformRouter.js +0 -108
- package/lib/cjs/services/PlatformRouter.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/createHandlerMetadata.js +0 -49
- package/lib/cjs/utils/createHandlerMetadata.js.map +0 -1
- package/lib/cjs/utils/importProviders.js +0 -29
- package/lib/cjs/utils/importProviders.js.map +0 -1
- package/lib/cjs/utils/useCtxHandler.js +0 -15
- package/lib/cjs/utils/useCtxHandler.js.map +0 -1
- package/lib/esm/builder/PlatformControllerBuilder.js +0 -76
- package/lib/esm/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js +0 -2
- package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js.map +0 -1
- package/lib/esm/domain/ControllerProvider.js +0 -47
- package/lib/esm/domain/ControllerProvider.js.map +0 -1
- package/lib/esm/domain/HandlerMetadata.js +0 -53
- package/lib/esm/domain/HandlerMetadata.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/middlewares/bindEndpointMiddleware.js +0 -9
- package/lib/esm/middlewares/bindEndpointMiddleware.js.map +0 -1
- package/lib/esm/services/PlatformRouter.js +0 -105
- package/lib/esm/services/PlatformRouter.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/createHandlerMetadata.js +0 -45
- package/lib/esm/utils/createHandlerMetadata.js.map +0 -1
- package/lib/esm/utils/importProviders.js +0 -25
- package/lib/esm/utils/importProviders.js.map +0 -1
- package/lib/esm/utils/useCtxHandler.js +0 -11
- package/lib/esm/utils/useCtxHandler.js.map +0 -1
- package/lib/types/builder/PlatformControllerBuilder.d.ts +0 -18
- package/lib/types/config/interfaces/EndpointDirectoriesSettings.d.ts +0 -3
- package/lib/types/domain/ControllerProvider.d.ts +0 -24
- package/lib/types/domain/HandlerMetadata.d.ts +0 -32
- package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +0 -2
- package/lib/types/middlewares/bindEndpointMiddleware.d.ts +0 -6
- package/lib/types/services/PlatformRouter.d.ts +0 -51
- package/lib/types/utils/__mock__/Test1.d.ts +0 -3
- package/lib/types/utils/__mock__/Test2.d.ts +0 -3
- package/lib/types/utils/createHandlerMetadata.d.ts +0 -8
- package/lib/types/utils/importProviders.d.ts +0 -10
- package/lib/types/utils/useCtxHandler.d.ts +0 -13
|
@@ -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,qC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Mount, 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"]}
|
|
@@ -9,18 +9,20 @@ function printRoutes(routes) {
|
|
|
9
9
|
PUT: "blue",
|
|
10
10
|
DELETE: "red",
|
|
11
11
|
PATCH: "magenta",
|
|
12
|
-
ALL: "cyan"
|
|
12
|
+
ALL: "cyan",
|
|
13
|
+
STATICS: "white"
|
|
13
14
|
};
|
|
14
15
|
const list = routes.map((route) => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const method = route.method.toUpperCase();
|
|
17
|
+
return {
|
|
18
|
+
...route,
|
|
19
|
+
method: {
|
|
20
|
+
length: method.length,
|
|
21
|
+
toString: () => {
|
|
22
|
+
return (0, logger_1.colorize)(method, mapColor[method]);
|
|
23
|
+
}
|
|
21
24
|
}
|
|
22
25
|
};
|
|
23
|
-
return obj;
|
|
24
26
|
});
|
|
25
27
|
const str = logger_1.$log.drawTable(list, {
|
|
26
28
|
padding: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"printRoutes.js","sourceRoot":"","sources":["../../../src/utils/printRoutes.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAG5C,SAAgB,WAAW,CAAC,MAA8B;IACxD,MAAM,QAAQ,GAA4B;QACxC,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,MAAM;QACX,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"printRoutes.js","sourceRoot":"","sources":["../../../src/utils/printRoutes.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAG5C,SAAgB,WAAW,CAAC,MAA8B;IACxD,MAAM,QAAQ,GAA4B;QACxC,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,MAAM;QACX,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,MAAM;QACX,OAAO,EAAE,OAAO;KACjB,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAChC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAE1C,OAAO;YACL,GAAG,KAAK;YACR,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,QAAQ,EAAE,GAAG,EAAE;oBACb,OAAO,IAAA,iBAAQ,EAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,CAAC;aACF;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,aAAI,CAAC,SAAS,CAAC,IAAI,EAAE;QAC/B,OAAO,EAAE,CAAC;QACV,MAAM,EAAE;YACN,MAAM,EAAE,QAAQ;YAChB,GAAG,EAAE,UAAU;YACf,IAAI,EAAE,cAAc;SACrB;KACF,CAAC,CAAC;IAEH,OAAO,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;AAC3B,CAAC;AAnCD,kCAmCC","sourcesContent":["import {$log, colorize} from \"@tsed/logger\";\nimport {PlatformRouteDetails} from \"../domain/PlatformRouteDetails\";\n\nexport function printRoutes(routes: PlatformRouteDetails[]) {\n const mapColor: {[key: string]: string} = {\n GET: \"green\",\n POST: \"yellow\",\n PUT: \"blue\",\n DELETE: \"red\",\n PATCH: \"magenta\",\n ALL: \"cyan\",\n STATICS: \"white\"\n };\n\n const list = routes.map((route) => {\n const method = route.method.toUpperCase();\n\n return {\n ...route,\n method: {\n length: method.length,\n toString: () => {\n return colorize(method, mapColor[method]);\n }\n }\n };\n });\n\n const str = $log.drawTable(list, {\n padding: 1,\n header: {\n method: \"Method\",\n url: \"Endpoint\",\n name: \"Class method\"\n }\n });\n\n return \"\\n\" + str.trim();\n}\n"]}
|
|
@@ -1,22 +1,13 @@
|
|
|
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
|
*/
|
|
16
7
|
function setResponseHeaders(ctx) {
|
|
17
8
|
const { response, endpoint } = ctx;
|
|
18
9
|
const { operation } = endpoint;
|
|
19
|
-
if (
|
|
10
|
+
if (ctx.isDone()) {
|
|
20
11
|
return;
|
|
21
12
|
}
|
|
22
13
|
if (!response.hasStatus()) {
|
|
@@ -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,GAAG,CAAC,MAAM,EAAE,EAAE;QAChB,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,CAAQ,EAAE,EAAE;QACrD,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 (ctx.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]: any[]) => {\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,52 +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 { createInjector } from "../utils/createInjector.js";
|
|
13
|
-
import { printRoutes } from "../utils/printRoutes.js";
|
|
6
|
+
import { PlatformApplication } from "../services/PlatformApplication.js";
|
|
14
7
|
import { createHttpServer } from "../utils/createHttpServer.js";
|
|
15
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";
|
|
16
13
|
/**
|
|
17
14
|
* @platform
|
|
18
15
|
*/
|
|
19
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 = [];
|
|
20
27
|
constructor(adapter, module, settings) {
|
|
21
|
-
this
|
|
22
|
-
|
|
23
|
-
this.current = new Date();
|
|
24
|
-
_PlatformBuilder_injector.set(this, void 0);
|
|
25
|
-
_PlatformBuilder_rootModule.set(this, void 0);
|
|
26
|
-
_PlatformBuilder_adapter.set(this, void 0);
|
|
27
|
-
_PlatformBuilder_promise.set(this, void 0);
|
|
28
|
-
_PlatformBuilder_servers.set(this, void 0);
|
|
29
|
-
_PlatformBuilder_listeners.set(this, []);
|
|
30
|
-
__classPrivateFieldSet(this, _PlatformBuilder_rootModule, module, "f");
|
|
28
|
+
this.#rootModule = module;
|
|
29
|
+
const configuration = getConfiguration(settings, module);
|
|
31
30
|
const adapterKlass = adapter || PlatformBuilder.adapter;
|
|
32
31
|
const name = nameOf(adapterKlass).replace("Platform", "").toLowerCase();
|
|
33
|
-
const configuration = getConfiguration(settings, module);
|
|
34
32
|
configuration.PLATFORM_NAME = name;
|
|
35
33
|
this.name = name;
|
|
36
|
-
|
|
34
|
+
this.#injector = createInjector({
|
|
37
35
|
adapter: adapterKlass,
|
|
38
36
|
settings: configuration
|
|
39
|
-
})
|
|
40
|
-
|
|
37
|
+
});
|
|
38
|
+
this.#adapter = this.#injector.get(PlatformAdapter);
|
|
41
39
|
this.createHttpServers();
|
|
42
|
-
|
|
40
|
+
this.#adapter.onInit && this.#adapter.onInit();
|
|
43
41
|
this.log("Injector created...");
|
|
44
42
|
}
|
|
45
43
|
get injector() {
|
|
46
|
-
return
|
|
44
|
+
return this.#injector;
|
|
47
45
|
}
|
|
48
46
|
get rootModule() {
|
|
49
|
-
return
|
|
47
|
+
return this.#injector.get(this.#rootModule);
|
|
50
48
|
}
|
|
51
49
|
get app() {
|
|
52
50
|
return this.injector.get(PlatformApplication);
|
|
@@ -55,7 +53,7 @@ export class PlatformBuilder {
|
|
|
55
53
|
return this.injector.get(Platform);
|
|
56
54
|
}
|
|
57
55
|
get adapter() {
|
|
58
|
-
return
|
|
56
|
+
return this.#adapter;
|
|
59
57
|
}
|
|
60
58
|
/**
|
|
61
59
|
* Return the settings configured by the decorator @@Configuration@@.
|
|
@@ -85,15 +83,13 @@ export class PlatformBuilder {
|
|
|
85
83
|
return this.injector.logger;
|
|
86
84
|
}
|
|
87
85
|
get disableBootstrapLog() {
|
|
88
|
-
|
|
89
|
-
return (_a = this.settings.logger) === null || _a === void 0 ? void 0 : _a.disableBootstrapLog;
|
|
86
|
+
return this.settings.get("logger.disableBootstrapLog");
|
|
90
87
|
}
|
|
91
88
|
static create(module, settings) {
|
|
92
89
|
return this.build(module, {
|
|
93
90
|
httpsPort: false,
|
|
94
91
|
httpPort: false,
|
|
95
|
-
...settings
|
|
96
|
-
disableComponentsScan: true
|
|
92
|
+
...settings
|
|
97
93
|
});
|
|
98
94
|
}
|
|
99
95
|
static build(module, { adapter, ...settings }) {
|
|
@@ -109,7 +105,7 @@ export class PlatformBuilder {
|
|
|
109
105
|
}
|
|
110
106
|
callback(req, res) {
|
|
111
107
|
if (req && res) {
|
|
112
|
-
return this.
|
|
108
|
+
return this.callback()(req, res);
|
|
113
109
|
}
|
|
114
110
|
return this.app.callback();
|
|
115
111
|
}
|
|
@@ -121,7 +117,7 @@ export class PlatformBuilder {
|
|
|
121
117
|
* @param classes
|
|
122
118
|
*/
|
|
123
119
|
addComponents(classes) {
|
|
124
|
-
this.settings.
|
|
120
|
+
this.settings.set("imports", this.settings.get("imports", []).concat(classes));
|
|
125
121
|
return this;
|
|
126
122
|
}
|
|
127
123
|
/**
|
|
@@ -145,32 +141,26 @@ export class PlatformBuilder {
|
|
|
145
141
|
* @param {any[]} controllers
|
|
146
142
|
*/
|
|
147
143
|
addControllers(endpoint, controllers) {
|
|
148
|
-
|
|
144
|
+
[].concat(controllers).forEach((token) => {
|
|
145
|
+
this.settings.routes.push({ token, route: endpoint });
|
|
146
|
+
});
|
|
149
147
|
}
|
|
150
148
|
async runLifecycle() {
|
|
151
|
-
|
|
152
|
-
await this.importProviders();
|
|
149
|
+
setLoggerConfiguration(this.injector);
|
|
153
150
|
await this.loadInjector();
|
|
154
|
-
|
|
155
|
-
__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").useRouter && __classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").useRouter();
|
|
151
|
+
this.#adapter.useContext();
|
|
156
152
|
await this.loadRoutes();
|
|
157
|
-
await this.logRoutes();
|
|
158
153
|
return this;
|
|
159
154
|
}
|
|
160
155
|
async loadInjector() {
|
|
161
156
|
const { injector } = this;
|
|
162
157
|
this.log("Build providers");
|
|
163
|
-
|
|
164
|
-
container.addProvider(__classPrivateFieldGet(this, _PlatformBuilder_rootModule, "f"), {
|
|
165
|
-
type: "server:module",
|
|
166
|
-
scope: ProviderScope.SINGLETON
|
|
167
|
-
});
|
|
168
|
-
await injector.load(container);
|
|
158
|
+
await injector.loadModule(this.#rootModule);
|
|
169
159
|
this.log("Settings and injector loaded...");
|
|
170
160
|
await this.callHook("$afterInit");
|
|
171
161
|
}
|
|
172
162
|
async listen(network = true) {
|
|
173
|
-
if (!
|
|
163
|
+
if (!this.#promise) {
|
|
174
164
|
await this.bootstrap();
|
|
175
165
|
}
|
|
176
166
|
await this.callHook("$beforeListen");
|
|
@@ -183,7 +173,7 @@ export class PlatformBuilder {
|
|
|
183
173
|
async stop() {
|
|
184
174
|
await this.callHook("$onDestroy");
|
|
185
175
|
await this.injector.destroy();
|
|
186
|
-
|
|
176
|
+
this.#listeners.map((server) => {
|
|
187
177
|
return new Promise((resolve) => server.close(() => resolve(undefined)));
|
|
188
178
|
});
|
|
189
179
|
}
|
|
@@ -216,14 +206,13 @@ export class PlatformBuilder {
|
|
|
216
206
|
return this;
|
|
217
207
|
}
|
|
218
208
|
async bootstrap() {
|
|
219
|
-
|
|
220
|
-
return
|
|
209
|
+
this.#promise = this.#promise || this.runLifecycle();
|
|
210
|
+
return this.#promise;
|
|
221
211
|
}
|
|
222
212
|
async loadRoutes() {
|
|
223
|
-
|
|
224
|
-
__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes && (await __classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes());
|
|
213
|
+
this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());
|
|
225
214
|
// istanbul ignore next
|
|
226
|
-
if (
|
|
215
|
+
if (this.settings.get("logger.level") !== "off") {
|
|
227
216
|
const { PlatformLogMiddleware } = await import("@tsed/platform-log-middleware");
|
|
228
217
|
this.app.use(PlatformLogMiddleware);
|
|
229
218
|
}
|
|
@@ -239,20 +228,19 @@ export class PlatformBuilder {
|
|
|
239
228
|
await this.callHook("$onRoutesInit");
|
|
240
229
|
await this.loadStatics("$afterRoutesInit");
|
|
241
230
|
await this.callHook("$afterRoutesInit");
|
|
242
|
-
|
|
231
|
+
this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());
|
|
232
|
+
await this.mapRouters();
|
|
233
|
+
}
|
|
234
|
+
async mapRouters() {
|
|
235
|
+
const layers = this.platform.getLayers();
|
|
236
|
+
this.#adapter.mapLayers(layers);
|
|
237
|
+
return this.logRoutes(layers.filter((layer) => layer.isProvider()));
|
|
243
238
|
}
|
|
244
239
|
diff() {
|
|
245
240
|
const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);
|
|
246
241
|
this.current = new Date();
|
|
247
242
|
return ms;
|
|
248
243
|
}
|
|
249
|
-
async importProviders() {
|
|
250
|
-
this.injector.logger.debug("Scan components");
|
|
251
|
-
const providers = await importProviders(this.injector.settings, ["imports", "mount", "componentsScan"]);
|
|
252
|
-
const routes = providers.filter((provider) => !!provider.route).map(({ route, token }) => ({ route, token }));
|
|
253
|
-
this.settings.set("routes", routes);
|
|
254
|
-
this.log("Providers loaded...");
|
|
255
|
-
}
|
|
256
244
|
/**
|
|
257
245
|
* Load middlewares from configuration for the given hook
|
|
258
246
|
* @param hook
|
|
@@ -264,19 +252,26 @@ export class PlatformBuilder {
|
|
|
264
252
|
});
|
|
265
253
|
}
|
|
266
254
|
createHttpServers() {
|
|
267
|
-
|
|
255
|
+
this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(Boolean);
|
|
268
256
|
}
|
|
269
257
|
async listenServers() {
|
|
270
|
-
|
|
258
|
+
this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));
|
|
271
259
|
}
|
|
272
|
-
async logRoutes() {
|
|
273
|
-
|
|
274
|
-
const { logger, platform } = this;
|
|
260
|
+
async logRoutes(layers) {
|
|
261
|
+
const { logger } = this;
|
|
275
262
|
this.log("Routes mounted...");
|
|
276
|
-
if (!
|
|
277
|
-
|
|
263
|
+
if (!this.settings.get("logger.disableRoutesSummary") && !this.disableBootstrapLog) {
|
|
264
|
+
const routes = layers.map((layer) => {
|
|
265
|
+
return {
|
|
266
|
+
url: layer.path,
|
|
267
|
+
method: layer.method,
|
|
268
|
+
name: layer.opts.name || `${layer.provider.className}.constructor()`,
|
|
269
|
+
className: layer.opts.className || layer.provider.className,
|
|
270
|
+
methodClassName: layer.opts.methodClassName || ""
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
logger.info(printRoutes(await this.injector.alterAsync("$logRoutes", routes)));
|
|
278
274
|
}
|
|
279
275
|
}
|
|
280
276
|
}
|
|
281
|
-
_PlatformBuilder_injector = new WeakMap(), _PlatformBuilder_rootModule = new WeakMap(), _PlatformBuilder_adapter = new WeakMap(), _PlatformBuilder_promise = new WeakMap(), _PlatformBuilder_servers = new WeakMap(), _PlatformBuilder_listeners = new WeakMap();
|
|
282
277
|
//# sourceMappingURL=PlatformBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,MAAM,EAAO,MAAM,YAAY,CAAC;AACxC,OAAO,EAAC,MAAM,EAAE,eAAe,EAAiC,aAAa,EAAE,cAAc,EAAC,MAAM,UAAU,CAAC;AAC/G,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAC,eAAe,EAA0B,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAC,eAAe,EAAC,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAG7D;;GAEG;AACH,MAAM,OAAO,eAAe;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CAAC,CAAC;IACL,CAAC;IAES,iBAAiB;QACzB,uBAAA,IAAI,4BAAY,CAAC,gBAAgB,CAAC,uBAAA,IAAI,iCAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,iBAAiB,CAAC,uBAAA,IAAI,iCAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAC5H,OAAO,CACC,MAAA,CAAC;IACb,CAAC;IAES,KAAK,CAAC,aAAa;QAC3B,uBAAA,IAAI,8BAAc,MAAM,OAAO,CAAC,GAAG,CAAC,uBAAA,IAAI,gCAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,MAAA,CAAC;IAC7E,CAAC;IAES,KAAK,CAAC,SAAS;;QACvB,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC;QAEhC,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAE9B,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,0CAAE,oBAAoB,CAAA,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC5E,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9F;IACH,CAAC;CACF","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, createContainer, InjectorService, ProviderOpts, ProviderScope, setLoggerLevel} 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 {importProviders} from \"../utils/importProviders\";\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 const adapterKlass: Type<PlatformAdapter<App, Router>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n const configuration = getConfiguration(settings, module);\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 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: 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: any | string | (any | string)[]) {\n this.settings.mount[endpoint] = (this.settings.mount[endpoint] || []).concat(controllers);\n }\n\n public async runLifecycle() {\n setLoggerLevel(this.injector);\n\n await this.importProviders();\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 const container = createContainer();\n\n container.addProvider(this.#rootModule, {\n type: \"server:module\",\n scope: ProviderScope.SINGLETON\n });\n\n await injector.load(container);\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 protected async importProviders() {\n this.injector.logger.debug(\"Scan components\");\n\n const providers = await importProviders(this.injector.settings, [\"imports\", \"mount\", \"componentsScan\"]);\n const routes = providers.filter((provider) => !!provider.route).map(({route, token}) => ({route, token}));\n\n this.settings.set(\"routes\", routes);\n this.log(\"Providers loaded...\");\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,EAA+C,sBAAsB,EAAgB,MAAM,UAAU,CAAC;AACpH,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAOjE,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,CAA6B;IAEzC,IAAI,GAAW,EAAE,CAAC;IACjB,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;IACtB,SAAS,CAAkB;IAC3B,WAAW,CAAY;IACvB,QAAQ,CAAuB;IACxC,QAAQ,CAAgB;IACxB,QAAQ,CAA2C;IACnD,UAAU,GAA8B,EAAE,CAAC;IAE3C,YAAsB,OAA+C,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,MAAM;oBACpB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,SAAS,gBAAgB;oBACpE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS;oBAC3D,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE;iBAC1B,CAAC;YAC5B,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;SAChF;IACH,CAAC;CACF","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, runInContext, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport {PlatformLayer} from \"@tsed/platform-router\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport type Https from \"https\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {PlatformRouteDetails} from \"../domain/PlatformRouteDetails\";\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> {\n public static adapter: Type<PlatformAdapter<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>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n\n const configuration = getConfiguration(settings, module);\n const adapterKlass: Type<PlatformAdapter<App>> = 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>>(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> {\n return this.injector.get<PlatformApplication<App>>(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>(module: Type<any>, settings: PlatformBuilderSettings<App>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings\n });\n }\n\n static build<App = TsED.Application>(module: Type<any>, {adapter, ...settings}: PlatformBuilderSettings<App>) {\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>(module: Type<any>, settings: PlatformBuilderSettings<App>) {\n return this.build<App>(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.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();\n\n await this.loadRoutes();\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 await this.mapRouters();\n }\n\n protected async mapRouters() {\n const layers = this.platform.getLayers();\n\n this.#adapter.mapLayers(layers);\n\n return this.logRoutes(layers.filter((layer) => layer.isProvider()));\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(layers: PlatformLayer[]) {\n const {logger} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.get(\"logger.disableRoutesSummary\") && !this.disableBootstrapLog) {\n const routes: PlatformRouteDetails[] = layers.map((layer) => {\n return {\n url: layer.path,\n method: layer.method,\n name: layer.opts.name || `${layer.provider.className}.constructor()`,\n className: layer.opts.className || layer.provider.className,\n methodClassName: layer.opts.methodClassName || \"\"\n } as PlatformRouteDetails;\n });\n\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", routes)));\n }\n }\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,24 +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
|
-
get componentsScan() {
|
|
62
|
-
return this.resolve(this.getRaw("componentsScan"));
|
|
63
|
-
}
|
|
64
|
-
set componentsScan(value) {
|
|
65
|
-
this.setRaw("componentsScan", value);
|
|
66
|
-
}
|
|
67
42
|
get statics() {
|
|
68
43
|
return this.getRaw("statics") || this.getRaw("serveStatic") || {};
|
|
69
44
|
}
|
|
@@ -76,51 +51,12 @@ let PlatformConfiguration = class PlatformConfiguration extends DIConfiguration
|
|
|
76
51
|
set acceptMimes(value) {
|
|
77
52
|
this.setRaw("acceptMimes", value || []);
|
|
78
53
|
}
|
|
79
|
-
get debug() {
|
|
80
|
-
return this.logger.level === "debug";
|
|
81
|
-
}
|
|
82
|
-
set debug(debug) {
|
|
83
|
-
this.logger = { ...this.logger, level: debug ? "debug" : "info" };
|
|
84
|
-
}
|
|
85
54
|
get converter() {
|
|
86
55
|
return this.get("converter") || {};
|
|
87
56
|
}
|
|
88
57
|
set converter(options) {
|
|
89
58
|
this.setRaw("converter", options);
|
|
90
59
|
}
|
|
91
|
-
get logger() {
|
|
92
|
-
return this.get("logger");
|
|
93
|
-
}
|
|
94
|
-
set logger(value) {
|
|
95
|
-
const logger = { ...this.logger, ...value };
|
|
96
|
-
logger.debug = logger.level === "debug";
|
|
97
|
-
this.setRaw("logger", logger);
|
|
98
|
-
this.setRaw("debug", logger.debug);
|
|
99
|
-
if (logger.format) {
|
|
100
|
-
$log.appenders.set("stdout", {
|
|
101
|
-
type: "stdout",
|
|
102
|
-
levels: ["info", "debug"],
|
|
103
|
-
layout: {
|
|
104
|
-
type: "pattern",
|
|
105
|
-
pattern: logger.format
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
$log.appenders.set("stderr", {
|
|
109
|
-
levels: ["trace", "fatal", "error", "warn"],
|
|
110
|
-
type: "stderr",
|
|
111
|
-
layout: {
|
|
112
|
-
type: "pattern",
|
|
113
|
-
pattern: logger.format
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
get exclude() {
|
|
119
|
-
return this.get("exclude");
|
|
120
|
-
}
|
|
121
|
-
set exclude(exclude) {
|
|
122
|
-
this.setRaw("exclude", exclude);
|
|
123
|
-
}
|
|
124
60
|
get additionalProperties() {
|
|
125
61
|
return this.get("converter.additionalProperties") === "accept";
|
|
126
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,
|
|
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,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,UAAU,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"]}
|