jimpex 7.0.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/LICENSE +1 -1
- package/README.md +446 -434
- package/dist/app/index.d.ts +13 -0
- package/dist/app/index.js +19 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/jimpex.d.ts +13 -0
- package/dist/app/jimpex.js +440 -0
- package/dist/app/jimpex.js.map +1 -0
- package/dist/controllers/common/config.d.ts +78 -0
- package/dist/controllers/common/config.js +89 -0
- package/dist/controllers/common/config.js.map +1 -0
- package/dist/controllers/common/health.d.ts +82 -0
- package/dist/controllers/common/health.js +97 -0
- package/dist/controllers/common/health.js.map +1 -0
- package/dist/controllers/common/index.d.ts +21 -0
- package/dist/controllers/common/index.js +21 -0
- package/dist/controllers/common/index.js.map +1 -0
- package/dist/controllers/common/statics.d.ts +215 -0
- package/dist/controllers/common/statics.js +202 -0
- package/dist/controllers/common/statics.js.map +1 -0
- package/dist/controllers/index.d.ts +24 -0
- package/dist/controllers/index.js +20 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/utils/gateway.d.ts +724 -0
- package/dist/controllers/utils/gateway.js +425 -0
- package/dist/controllers/utils/gateway.js.map +1 -0
- package/dist/controllers/utils/index.d.ts +16 -0
- package/dist/controllers/utils/index.js +19 -0
- package/dist/controllers/utils/index.js.map +1 -0
- package/dist/esm/app/index.js +2 -0
- package/dist/esm/app/index.js.map +1 -0
- package/dist/esm/app/jimpex.js +415 -0
- package/dist/esm/app/jimpex.js.map +1 -0
- package/dist/esm/chunk-T2T6Q22Z.js +11 -0
- package/dist/esm/chunk-T2T6Q22Z.js.map +1 -0
- package/dist/esm/controllers/common/config.js +62 -0
- package/dist/esm/controllers/common/config.js.map +1 -0
- package/dist/esm/controllers/common/health.js +70 -0
- package/dist/esm/controllers/common/health.js.map +1 -0
- package/dist/esm/controllers/common/index.js +4 -0
- package/dist/esm/controllers/common/index.js.map +1 -0
- package/dist/esm/controllers/common/statics.js +173 -0
- package/dist/esm/controllers/common/statics.js.map +1 -0
- package/dist/esm/controllers/index.js +3 -0
- package/dist/esm/controllers/index.js.map +1 -0
- package/dist/esm/controllers/utils/gateway.js +404 -0
- package/dist/esm/controllers/utils/gateway.js.map +1 -0
- package/dist/esm/controllers/utils/index.js +2 -0
- package/dist/esm/controllers/utils/index.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/middlewares/common/errorHandler.js +92 -0
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
- package/dist/esm/middlewares/common/forceHTTPS.js +41 -0
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/esm/middlewares/common/hsts.js +53 -0
- package/dist/esm/middlewares/common/hsts.js.map +1 -0
- package/dist/esm/middlewares/common/index.js +4 -0
- package/dist/esm/middlewares/common/index.js.map +1 -0
- package/dist/esm/middlewares/html/fastHTML.js +104 -0
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
- package/dist/esm/middlewares/html/index.js +3 -0
- package/dist/esm/middlewares/html/index.js.map +1 -0
- package/dist/esm/middlewares/html/showHTML.js +68 -0
- package/dist/esm/middlewares/html/showHTML.js.map +1 -0
- package/dist/esm/middlewares/index.js +4 -0
- package/dist/esm/middlewares/index.js.map +1 -0
- package/dist/esm/middlewares/utils/index.js +2 -0
- package/dist/esm/middlewares/utils/index.js.map +1 -0
- package/dist/esm/middlewares/utils/versionValidator.js +101 -0
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/esm/services/common/appError.js +52 -0
- package/dist/esm/services/common/appError.js.map +1 -0
- package/dist/esm/services/common/httpError.js +19 -0
- package/dist/esm/services/common/httpError.js.map +1 -0
- package/dist/esm/services/common/index.js +17 -0
- package/dist/esm/services/common/index.js.map +1 -0
- package/dist/esm/services/common/sendFile.js +27 -0
- package/dist/esm/services/common/sendFile.js.map +1 -0
- package/dist/esm/services/frontend/frontendFs.js +38 -0
- package/dist/esm/services/frontend/frontendFs.js.map +1 -0
- package/dist/esm/services/frontend/index.js +11 -0
- package/dist/esm/services/frontend/index.js.map +1 -0
- package/dist/esm/services/html/htmlGenerator.js +144 -0
- package/dist/esm/services/html/htmlGenerator.js.map +1 -0
- package/dist/esm/services/html/index.js +11 -0
- package/dist/esm/services/html/index.js.map +1 -0
- package/dist/esm/services/http/apiClient.js +71 -0
- package/dist/esm/services/http/apiClient.js.map +1 -0
- package/dist/esm/services/http/http.js +125 -0
- package/dist/esm/services/http/http.js.map +1 -0
- package/dist/esm/services/http/index.js +17 -0
- package/dist/esm/services/http/index.js.map +1 -0
- package/dist/esm/services/http/responsesBuilder.js +105 -0
- package/dist/esm/services/http/responsesBuilder.js.map +1 -0
- package/dist/esm/services/index.js +6 -0
- package/dist/esm/services/index.js.map +1 -0
- package/dist/esm/services/utils/ensureBearerToken.js +78 -0
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/esm/services/utils/index.js +11 -0
- package/dist/esm/services/utils/index.js.map +1 -0
- package/dist/esm/types/events.js +1 -0
- package/dist/esm/types/events.js.map +1 -0
- package/dist/esm/types/express.js +1 -0
- package/dist/esm/types/express.js.map +1 -0
- package/dist/esm/types/http.js +1 -0
- package/dist/esm/types/http.js.map +1 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/options.js.map +1 -0
- package/dist/esm/types/utils.js +1 -0
- package/dist/esm/types/utils.js.map +1 -0
- package/dist/esm/types/wootils.js +1 -0
- package/dist/esm/types/wootils.js.map +1 -0
- package/dist/esm/utils/fns/index.js +5 -0
- package/dist/esm/utils/fns/index.js.map +1 -0
- package/dist/esm/utils/fns/others.js +6 -0
- package/dist/esm/utils/fns/others.js.map +1 -0
- package/dist/esm/utils/fns/routes.js +25 -0
- package/dist/esm/utils/fns/routes.js.map +1 -0
- package/dist/esm/utils/fns/statuses.js +6 -0
- package/dist/esm/utils/fns/statuses.js.map +1 -0
- package/dist/esm/utils/fns/text.js +6 -0
- package/dist/esm/utils/fns/text.js.map +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/wrappers.js +41 -0
- package/dist/esm/utils/wrappers.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jimpex-7eaee271.d.ts +1278 -0
- package/dist/middlewares/common/errorHandler.d.ts +131 -0
- package/dist/middlewares/common/errorHandler.js +119 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +68 -0
- package/dist/middlewares/common/forceHTTPS.js +68 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/middlewares/common/hsts.d.ts +109 -0
- package/dist/middlewares/common/hsts.js +80 -0
- package/dist/middlewares/common/hsts.js.map +1 -0
- package/dist/middlewares/common/index.d.ts +21 -0
- package/dist/middlewares/common/index.js +21 -0
- package/dist/middlewares/common/index.js.map +1 -0
- package/dist/middlewares/html/fastHTML.d.ts +180 -0
- package/dist/middlewares/html/fastHTML.js +131 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -0
- package/dist/middlewares/html/index.d.ts +21 -0
- package/dist/middlewares/html/index.js +20 -0
- package/dist/middlewares/html/index.js.map +1 -0
- package/dist/middlewares/html/showHTML.d.ts +127 -0
- package/dist/middlewares/html/showHTML.js +95 -0
- package/dist/middlewares/html/showHTML.js.map +1 -0
- package/dist/middlewares/index.d.ts +30 -0
- package/dist/middlewares/index.js +21 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/utils/index.d.ts +19 -0
- package/dist/middlewares/utils/index.js +19 -0
- package/dist/middlewares/utils/index.js.map +1 -0
- package/dist/middlewares/utils/versionValidator.d.ts +214 -0
- package/dist/middlewares/utils/versionValidator.js +128 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/services/common/appError.d.ts +138 -0
- package/dist/services/common/appError.js +80 -0
- package/dist/services/common/appError.js.map +1 -0
- package/dist/services/common/httpError.d.ts +79 -0
- package/dist/services/common/httpError.js +44 -0
- package/dist/services/common/httpError.js.map +1 -0
- package/dist/services/common/index.d.ts +47 -0
- package/dist/services/common/index.js +41 -0
- package/dist/services/common/index.js.map +1 -0
- package/dist/services/common/sendFile.d.ts +102 -0
- package/dist/services/common/sendFile.js +51 -0
- package/dist/services/common/sendFile.js.map +1 -0
- package/dist/services/frontend/frontendFs.d.ts +96 -0
- package/dist/services/frontend/frontendFs.js +71 -0
- package/dist/services/frontend/frontendFs.js.map +1 -0
- package/dist/services/frontend/index.d.ts +40 -0
- package/dist/services/frontend/index.js +35 -0
- package/dist/services/frontend/index.js.map +1 -0
- package/dist/services/html/htmlGenerator.d.ts +237 -0
- package/dist/services/html/htmlGenerator.js +171 -0
- package/dist/services/html/htmlGenerator.js.map +1 -0
- package/dist/services/html/index.d.ts +43 -0
- package/dist/services/html/index.js +35 -0
- package/dist/services/html/index.js.map +1 -0
- package/dist/services/http/apiClient.d.ts +169 -0
- package/dist/services/http/apiClient.js +96 -0
- package/dist/services/http/apiClient.js.map +1 -0
- package/dist/services/http/http.d.ts +175 -0
- package/dist/services/http/http.js +158 -0
- package/dist/services/http/http.js.map +1 -0
- package/dist/services/http/index.d.ts +50 -0
- package/dist/services/http/index.js +41 -0
- package/dist/services/http/index.js.map +1 -0
- package/dist/services/http/responsesBuilder.d.ts +178 -0
- package/dist/services/http/responsesBuilder.js +132 -0
- package/dist/services/http/responsesBuilder.js.map +1 -0
- package/dist/services/index.d.ts +33 -0
- package/dist/services/index.js +23 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/utils/ensureBearerToken.d.ts +157 -0
- package/dist/services/utils/ensureBearerToken.js +105 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/services/utils/index.d.ts +43 -0
- package/dist/services/utils/index.js +35 -0
- package/dist/services/utils/index.js.map +1 -0
- package/dist/types/events.d.ts +13 -0
- package/dist/types/events.js +17 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/express.d.ts +10 -0
- package/dist/types/express.js +17 -0
- package/dist/types/express.js.map +1 -0
- package/dist/types/http.d.ts +79 -0
- package/dist/types/http.js +17 -0
- package/dist/types/http.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.ts +13 -0
- package/dist/types/options.js +17 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/utils.d.ts +48 -0
- package/dist/types/utils.js +17 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/types/wootils.d.ts +4 -0
- package/dist/types/wootils.js +17 -0
- package/dist/types/wootils.js.map +1 -0
- package/dist/utils/fns/index.d.ts +5 -0
- package/dist/utils/fns/index.js +22 -0
- package/dist/utils/fns/index.js.map +1 -0
- package/dist/utils/fns/others.d.ts +17 -0
- package/dist/utils/fns/others.js +29 -0
- package/dist/utils/fns/others.js.map +1 -0
- package/dist/utils/fns/routes.d.ts +39 -0
- package/dist/utils/fns/routes.js +51 -0
- package/dist/utils/fns/routes.js.map +1 -0
- package/dist/utils/fns/statuses.d.ts +45 -0
- package/dist/utils/fns/statuses.js +35 -0
- package/dist/utils/fns/statuses.js.map +1 -0
- package/dist/utils/fns/text.d.ts +9 -0
- package/dist/utils/fns/text.js +29 -0
- package/dist/utils/fns/text.js.map +1 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/wrappers.d.ts +13 -0
- package/dist/utils/wrappers.js +68 -0
- package/dist/utils/wrappers.js.map +1 -0
- package/examples/basic/404.html +12 -0
- package/examples/basic/README.md +30 -0
- package/examples/basic/app.ts +18 -0
- package/examples/basic/controller.ts +45 -0
- package/examples/basic/index.ts +19 -0
- package/examples/basic/middleware.ts +13 -0
- package/examples/basic/service.ts +11 -0
- package/package.json +59 -38
- package/src/app/index.ts +1 -0
- package/src/app/jimpex.ts +743 -0
- package/src/controllers/common/config.ts +115 -0
- package/src/controllers/common/health.ts +128 -0
- package/src/controllers/common/index.ts +3 -0
- package/src/controllers/common/statics.ts +380 -0
- package/src/controllers/index.ts +2 -0
- package/src/controllers/utils/gateway.ts +1186 -0
- package/src/controllers/utils/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/middlewares/common/errorHandler.ts +203 -0
- package/src/middlewares/common/forceHTTPS.ts +83 -0
- package/src/middlewares/common/hsts.ts +135 -0
- package/src/middlewares/common/index.ts +3 -0
- package/src/middlewares/html/fastHTML.ts +255 -0
- package/src/middlewares/html/index.ts +2 -0
- package/src/middlewares/html/showHTML.ts +165 -0
- package/src/middlewares/index.ts +3 -0
- package/src/middlewares/utils/index.ts +1 -0
- package/src/middlewares/utils/versionValidator.ts +289 -0
- package/src/services/common/appError.ts +158 -0
- package/src/services/common/httpError.ts +74 -0
- package/src/services/common/index.ts +29 -0
- package/src/services/common/sendFile.ts +106 -0
- package/src/services/frontend/frontendFs.ts +101 -0
- package/src/services/frontend/index.ts +21 -0
- package/src/services/html/htmlGenerator.ts +356 -0
- package/src/services/html/index.ts +21 -0
- package/src/services/http/apiClient.ts +221 -0
- package/src/services/http/http.ts +286 -0
- package/src/services/http/index.ts +29 -0
- package/src/services/http/responsesBuilder.ts +265 -0
- package/src/services/index.ts +5 -0
- package/src/services/utils/ensureBearerToken.ts +202 -0
- package/src/services/utils/index.ts +21 -0
- package/src/types/events.ts +303 -0
- package/src/types/express.ts +21 -0
- package/src/types/http.ts +77 -0
- package/src/types/index.ts +6 -0
- package/src/types/options.ts +248 -0
- package/src/types/utils.ts +52 -0
- package/src/types/wootils.ts +4 -0
- package/src/utils/fns/index.ts +4 -0
- package/src/utils/fns/others.ts +15 -0
- package/src/utils/fns/routes.ts +64 -0
- package/src/utils/fns/statuses.ts +44 -0
- package/src/utils/fns/text.ts +8 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/wrappers.ts +537 -0
- package/tsconfig.json +5 -8
- package/tsup.config.ts +10 -0
- package/src/app/index.js +0 -692
- package/src/constants/eventNames.js +0 -48
- package/src/constants/index.js +0 -7
- package/src/controllers/common/configuration.js +0 -116
- package/src/controllers/common/health.js +0 -79
- package/src/controllers/common/index.js +0 -7
- package/src/controllers/common/statics.js +0 -336
- package/src/controllers/index.js +0 -9
- package/src/controllers/utils/gateway.js +0 -1039
- package/src/controllers/utils/index.js +0 -3
- package/src/index.js +0 -30
- package/src/middlewares/common/errorHandler.js +0 -185
- package/src/middlewares/common/forceHTTPS.js +0 -80
- package/src/middlewares/common/hsts.js +0 -122
- package/src/middlewares/common/index.js +0 -7
- package/src/middlewares/html/fastHTML.js +0 -298
- package/src/middlewares/html/index.js +0 -5
- package/src/middlewares/html/showHTML.js +0 -167
- package/src/middlewares/index.js +0 -11
- package/src/middlewares/utils/index.js +0 -3
- package/src/middlewares/utils/versionValidator.js +0 -261
- package/src/services/common/appError.js +0 -136
- package/src/services/common/httpError.js +0 -60
- package/src/services/common/index.js +0 -25
- package/src/services/common/sendFile.js +0 -68
- package/src/services/frontend/frontendFs.js +0 -85
- package/src/services/frontend/index.js +0 -17
- package/src/services/html/htmlGenerator.js +0 -391
- package/src/services/html/index.js +0 -17
- package/src/services/http/apiClient.js +0 -148
- package/src/services/http/http.js +0 -256
- package/src/services/http/index.js +0 -25
- package/src/services/http/responsesBuilder.js +0 -193
- package/src/services/index.js +0 -15
- package/src/services/utils/ensureBearerToken.js +0 -147
- package/src/services/utils/index.js +0 -19
- package/src/types.js +0 -377
- package/src/utils/functions.js +0 -78
- package/src/utils/wrappers.js +0 -131
- package/types/app/index.d.ts +0 -417
- package/types/constants/eventNames.d.ts +0 -93
- package/types/constants/index.d.ts +0 -2
- package/types/controllers/common/configuration.d.ts +0 -71
- package/types/controllers/common/health.d.ts +0 -55
- package/types/controllers/common/index.d.ts +0 -4
- package/types/controllers/common/statics.d.ts +0 -271
- package/types/controllers/index.d.ts +0 -3
- package/types/controllers/utils/gateway.d.ts +0 -947
- package/types/controllers/utils/index.d.ts +0 -2
- package/types/index.d.ts +0 -15
- package/types/middlewares/common/errorHandler.d.ts +0 -143
- package/types/middlewares/common/forceHTTPS.d.ts +0 -64
- package/types/middlewares/common/hsts.d.ts +0 -111
- package/types/middlewares/common/index.d.ts +0 -4
- package/types/middlewares/html/fastHTML.d.ts +0 -238
- package/types/middlewares/html/index.d.ts +0 -3
- package/types/middlewares/html/showHTML.d.ts +0 -128
- package/types/middlewares/index.d.ts +0 -4
- package/types/middlewares/utils/index.d.ts +0 -2
- package/types/middlewares/utils/versionValidator.d.ts +0 -247
- package/types/services/common/appError.d.ts +0 -89
- package/types/services/common/httpError.d.ts +0 -37
- package/types/services/common/index.d.ts +0 -18
- package/types/services/common/sendFile.d.ts +0 -56
- package/types/services/frontend/frontendFs.d.ts +0 -72
- package/types/services/frontend/index.d.ts +0 -3
- package/types/services/html/htmlGenerator.d.ts +0 -298
- package/types/services/html/index.d.ts +0 -3
- package/types/services/http/apiClient.d.ts +0 -141
- package/types/services/http/http.d.ts +0 -159
- package/types/services/http/index.d.ts +0 -18
- package/types/services/http/responsesBuilder.d.ts +0 -140
- package/types/services/index.d.ts +0 -6
- package/types/services/utils/ensureBearerToken.d.ts +0 -137
- package/types/services/utils/index.d.ts +0 -16
- package/types/types.d.ts +0 -280
- package/types/utils/functions.d.ts +0 -55
- package/types/utils/wrappers.d.ts +0 -127
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { J as Jimpex, j as jimpex } from '../jimpex-7eaee271.js';
|
|
2
|
+
import '@homer0/jimple';
|
|
3
|
+
import '@homer0/events-hub';
|
|
4
|
+
import '../types/express.js';
|
|
5
|
+
import 'express';
|
|
6
|
+
import '../types/http.js';
|
|
7
|
+
import 'https';
|
|
8
|
+
import 'http';
|
|
9
|
+
import 'spdy';
|
|
10
|
+
import 'node-fetch';
|
|
11
|
+
import '@homer0/simple-config';
|
|
12
|
+
import '../types/utils.js';
|
|
13
|
+
import '@homer0/simple-logger';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var app_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(app_exports);
|
|
18
|
+
__reExport(app_exports, require("./jimpex"), module.exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/app/index.ts"],"sourcesContent":["export * from './jimpex';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,qBAAd;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '@homer0/jimple';
|
|
2
|
+
import '@homer0/events-hub';
|
|
3
|
+
export { J as Jimpex, j as jimpex } from '../jimpex-7eaee271.js';
|
|
4
|
+
import 'express';
|
|
5
|
+
import '../types/http.js';
|
|
6
|
+
import '../types/utils.js';
|
|
7
|
+
import '@homer0/simple-logger';
|
|
8
|
+
import '@homer0/simple-config';
|
|
9
|
+
import '../types/express.js';
|
|
10
|
+
import 'https';
|
|
11
|
+
import 'http';
|
|
12
|
+
import 'spdy';
|
|
13
|
+
import 'node-fetch';
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var __publicField = (obj, key, value) => {
|
|
27
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
var jimpex_exports = {};
|
|
31
|
+
__export(jimpex_exports, {
|
|
32
|
+
Jimpex: () => Jimpex,
|
|
33
|
+
jimpex: () => jimpex
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(jimpex_exports);
|
|
36
|
+
var path = __toESM(require("path"));
|
|
37
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
38
|
+
var import_https = require("https");
|
|
39
|
+
var import_jimple = require("@homer0/jimple");
|
|
40
|
+
var import_deep_assign = require("@homer0/deep-assign");
|
|
41
|
+
var import_simple_logger = require("@homer0/simple-logger");
|
|
42
|
+
var import_env_utils = require("@homer0/env-utils");
|
|
43
|
+
var import_package_info = require("@homer0/package-info");
|
|
44
|
+
var import_path_utils = require("@homer0/path-utils");
|
|
45
|
+
var import_root_file = require("@homer0/root-file");
|
|
46
|
+
var import_events_hub = require("@homer0/events-hub");
|
|
47
|
+
var import_simple_config = require("@homer0/simple-config");
|
|
48
|
+
var import_compression = __toESM(require("compression"));
|
|
49
|
+
var import_body_parser = __toESM(require("body-parser"));
|
|
50
|
+
var import_multer = __toESM(require("multer"));
|
|
51
|
+
var import_spdy = require("spdy");
|
|
52
|
+
var import_express = __toESM(require("express"));
|
|
53
|
+
var import_services = require("../services");
|
|
54
|
+
var import_utils = require("../utils");
|
|
55
|
+
class Jimpex extends import_jimple.Jimple {
|
|
56
|
+
constructor(options = {}, config = {}) {
|
|
57
|
+
super();
|
|
58
|
+
__publicField(this, "_options");
|
|
59
|
+
__publicField(this, "_express");
|
|
60
|
+
__publicField(this, "_configReady", false);
|
|
61
|
+
__publicField(this, "_server");
|
|
62
|
+
__publicField(this, "_instance");
|
|
63
|
+
__publicField(this, "_mountQueue", []);
|
|
64
|
+
__publicField(this, "_controlledRoutes", []);
|
|
65
|
+
this._options = (0, import_deep_assign.deepAssignWithOverwrite)(
|
|
66
|
+
{
|
|
67
|
+
filesizeLimit: "15MB",
|
|
68
|
+
boot: true,
|
|
69
|
+
path: {
|
|
70
|
+
appPath: "",
|
|
71
|
+
useParentPath: true
|
|
72
|
+
},
|
|
73
|
+
config: {
|
|
74
|
+
default: options?.config?.default || config,
|
|
75
|
+
name: "app",
|
|
76
|
+
path: "config/",
|
|
77
|
+
hasFolder: false,
|
|
78
|
+
loadFromEnvironment: true,
|
|
79
|
+
environmentVariable: "CONFIG",
|
|
80
|
+
defaultConfigFilename: "[app-name].config.js",
|
|
81
|
+
filenameFormat: "[app-name].[config-name].config.js"
|
|
82
|
+
},
|
|
83
|
+
statics: {
|
|
84
|
+
enabled: true,
|
|
85
|
+
onHome: false,
|
|
86
|
+
route: "statics"
|
|
87
|
+
},
|
|
88
|
+
express: {
|
|
89
|
+
trustProxy: true,
|
|
90
|
+
disableXPoweredBy: true,
|
|
91
|
+
compression: true,
|
|
92
|
+
bodyParser: true,
|
|
93
|
+
multer: true
|
|
94
|
+
},
|
|
95
|
+
services: {
|
|
96
|
+
common: true,
|
|
97
|
+
http: true,
|
|
98
|
+
utils: true
|
|
99
|
+
},
|
|
100
|
+
healthCheck: () => Promise.resolve(true)
|
|
101
|
+
},
|
|
102
|
+
options,
|
|
103
|
+
this._initOptions()
|
|
104
|
+
);
|
|
105
|
+
this._express = (0, import_express.default)();
|
|
106
|
+
this._setupCoreServices();
|
|
107
|
+
this._setupExpress();
|
|
108
|
+
this._configurePath();
|
|
109
|
+
this._init();
|
|
110
|
+
if (this._options.boot) {
|
|
111
|
+
this.boot();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
boot() {
|
|
115
|
+
}
|
|
116
|
+
disableTLSValidation() {
|
|
117
|
+
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
|
|
118
|
+
this.logger.warn("TLS validation has been disabled");
|
|
119
|
+
}
|
|
120
|
+
async start(onStart) {
|
|
121
|
+
await this._setupConfig();
|
|
122
|
+
const config = this.getConfig();
|
|
123
|
+
const port = config.get("port");
|
|
124
|
+
if (!port) {
|
|
125
|
+
throw new Error("No port configured");
|
|
126
|
+
}
|
|
127
|
+
this._emitEvent("beforeStart", { app: this });
|
|
128
|
+
this._server = await this._createServer();
|
|
129
|
+
this._instance = this._server.listen(port, () => {
|
|
130
|
+
this._emitEvent("start", { app: this });
|
|
131
|
+
this._mountResources();
|
|
132
|
+
this.logger.success(`Starting on port ${port}`);
|
|
133
|
+
this._emitEvent("afterStart", { app: this });
|
|
134
|
+
if (onStart) {
|
|
135
|
+
onStart(config);
|
|
136
|
+
}
|
|
137
|
+
this._emitEvent("afterStartCallback", { app: this });
|
|
138
|
+
});
|
|
139
|
+
return this._instance;
|
|
140
|
+
}
|
|
141
|
+
async listen(port, onStart) {
|
|
142
|
+
if (port) {
|
|
143
|
+
await this._setupConfig();
|
|
144
|
+
const config = this.getConfig();
|
|
145
|
+
config.set("port", port);
|
|
146
|
+
}
|
|
147
|
+
return this.start(onStart);
|
|
148
|
+
}
|
|
149
|
+
stop() {
|
|
150
|
+
if (!this._instance)
|
|
151
|
+
return;
|
|
152
|
+
this._emitEvent("beforeStop", { app: this });
|
|
153
|
+
this._instance.close();
|
|
154
|
+
this._instance = void 0;
|
|
155
|
+
this._emitEvent("afterStop", { app: this });
|
|
156
|
+
}
|
|
157
|
+
mount(route, controller) {
|
|
158
|
+
let useController;
|
|
159
|
+
if ("register" in controller && typeof controller.register === "function" && controller.provider === true) {
|
|
160
|
+
useController = controller.register(this, route);
|
|
161
|
+
} else if ("connect" in controller && typeof controller.connect === "function" && ("middleware" in controller && controller.middleware === true || "controller" in controller && controller.controller === true)) {
|
|
162
|
+
useController = controller;
|
|
163
|
+
} else {
|
|
164
|
+
useController = {
|
|
165
|
+
middleware: true,
|
|
166
|
+
connect: () => controller
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
this._mountQueue.push((server) => {
|
|
170
|
+
const connected = useController.connect(this, route);
|
|
171
|
+
if (!connected)
|
|
172
|
+
return;
|
|
173
|
+
const router = this._reduceWithEvent("controllerWillBeMounted", connected, {
|
|
174
|
+
route,
|
|
175
|
+
controller: useController,
|
|
176
|
+
app: this
|
|
177
|
+
});
|
|
178
|
+
server.use(route, router);
|
|
179
|
+
this._emitEvent("routeAdded", { route, app: this });
|
|
180
|
+
this._controlledRoutes.push(route);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
use(middleware) {
|
|
184
|
+
const useMiddleware = "register" in middleware && typeof middleware.register === "function" ? middleware.register(this) : middleware;
|
|
185
|
+
this._mountQueue.push((server) => {
|
|
186
|
+
if ("connect" in useMiddleware && typeof useMiddleware.connect === "function") {
|
|
187
|
+
const handler = useMiddleware.connect(this);
|
|
188
|
+
if (handler) {
|
|
189
|
+
server.use(
|
|
190
|
+
this._reduceWithEvent("middlewareWillBeUsed", handler, { app: this })
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
server.use(
|
|
196
|
+
this._reduceWithEvent(
|
|
197
|
+
"middlewareWillBeUsed",
|
|
198
|
+
useMiddleware,
|
|
199
|
+
{ app: this }
|
|
200
|
+
)
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
getConfig(setting, asArray = false) {
|
|
205
|
+
const config = this.try("config");
|
|
206
|
+
if (!config) {
|
|
207
|
+
throw new Error("The config service is not available until the app starts");
|
|
208
|
+
}
|
|
209
|
+
if (typeof setting === "undefined") {
|
|
210
|
+
return config;
|
|
211
|
+
}
|
|
212
|
+
return config.get(setting, asArray);
|
|
213
|
+
}
|
|
214
|
+
getRouter() {
|
|
215
|
+
return this.get("router");
|
|
216
|
+
}
|
|
217
|
+
get logger() {
|
|
218
|
+
return this.get("logger");
|
|
219
|
+
}
|
|
220
|
+
get express() {
|
|
221
|
+
return this._express;
|
|
222
|
+
}
|
|
223
|
+
get instance() {
|
|
224
|
+
return this._instance;
|
|
225
|
+
}
|
|
226
|
+
get options() {
|
|
227
|
+
return (0, import_deep_assign.deepAssignWithOverwrite)({}, this._options);
|
|
228
|
+
}
|
|
229
|
+
get eventsHub() {
|
|
230
|
+
return this.get("events");
|
|
231
|
+
}
|
|
232
|
+
get routes() {
|
|
233
|
+
return this._controlledRoutes.slice();
|
|
234
|
+
}
|
|
235
|
+
on(eventName, listener) {
|
|
236
|
+
return this.eventsHub.on(eventName, listener);
|
|
237
|
+
}
|
|
238
|
+
once(eventName, listener) {
|
|
239
|
+
return this.eventsHub.once(eventName, listener);
|
|
240
|
+
}
|
|
241
|
+
isHealthy() {
|
|
242
|
+
return this._options.healthCheck(this);
|
|
243
|
+
}
|
|
244
|
+
_init() {
|
|
245
|
+
}
|
|
246
|
+
_initOptions() {
|
|
247
|
+
return {};
|
|
248
|
+
}
|
|
249
|
+
_setupCoreServices() {
|
|
250
|
+
this.register(
|
|
251
|
+
(0, import_simple_logger.appLoggerProvider)({
|
|
252
|
+
serviceName: "logger"
|
|
253
|
+
})
|
|
254
|
+
);
|
|
255
|
+
this.register(import_env_utils.envUtilsProvider);
|
|
256
|
+
this.register(import_package_info.packageInfoProvider);
|
|
257
|
+
this.register(import_path_utils.pathUtilsProvider);
|
|
258
|
+
this.register(import_root_file.rootFileProvider);
|
|
259
|
+
const { services: enabledServices } = this._options;
|
|
260
|
+
if (enabledServices.common)
|
|
261
|
+
this.register(import_services.commonServicesProvider);
|
|
262
|
+
if (enabledServices.http)
|
|
263
|
+
this.register(import_services.httpServicesProvider);
|
|
264
|
+
if (enabledServices.utils)
|
|
265
|
+
this.register(import_services.utilsServicesProvider);
|
|
266
|
+
this.set("events", () => new import_events_hub.EventsHub());
|
|
267
|
+
this.set("statuses", () => import_utils.statuses);
|
|
268
|
+
}
|
|
269
|
+
_setupExpress() {
|
|
270
|
+
const { statics, filesizeLimit, express: expressOptions } = this._options;
|
|
271
|
+
if (expressOptions.trustProxy) {
|
|
272
|
+
this._express.enable("trust proxy");
|
|
273
|
+
}
|
|
274
|
+
if (expressOptions.disableXPoweredBy) {
|
|
275
|
+
this._express.disable("x-powered-by");
|
|
276
|
+
}
|
|
277
|
+
if (expressOptions.compression) {
|
|
278
|
+
this._express.use((0, import_compression.default)());
|
|
279
|
+
}
|
|
280
|
+
if (statics.enabled) {
|
|
281
|
+
this._addStaticsFolder(statics.route, statics.folder, statics.onHome);
|
|
282
|
+
}
|
|
283
|
+
if (expressOptions.bodyParser) {
|
|
284
|
+
this._express.use(
|
|
285
|
+
import_body_parser.default.json({
|
|
286
|
+
limit: filesizeLimit
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
this._express.use(
|
|
290
|
+
import_body_parser.default.urlencoded({
|
|
291
|
+
extended: true,
|
|
292
|
+
limit: filesizeLimit
|
|
293
|
+
})
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
if (expressOptions.multer) {
|
|
297
|
+
this._express.use((0, import_multer.default)().any());
|
|
298
|
+
}
|
|
299
|
+
this.set(
|
|
300
|
+
"router",
|
|
301
|
+
this.factory(() => import_express.default.Router())
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
_addStaticsFolder(route, folder = "", onHome = false) {
|
|
305
|
+
const location = onHome ? "home" : "app";
|
|
306
|
+
const staticRoute = route.replace(/^\/+/, "");
|
|
307
|
+
const pathUtils = this.get("pathUtils");
|
|
308
|
+
const staticFolder = pathUtils.joinFrom(location, folder || staticRoute);
|
|
309
|
+
this.mount(`/${staticRoute}`, {
|
|
310
|
+
connect: () => import_express.default.static(staticFolder),
|
|
311
|
+
controller: true
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
_configurePath() {
|
|
315
|
+
const pathUtils = this.get("pathUtils");
|
|
316
|
+
const {
|
|
317
|
+
path: { appPath, useParentPath }
|
|
318
|
+
} = this._options;
|
|
319
|
+
if (appPath) {
|
|
320
|
+
pathUtils.addLocation("app", appPath);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
let foundPath = false;
|
|
324
|
+
if (useParentPath) {
|
|
325
|
+
const stack = new Error().stack;
|
|
326
|
+
const stackList = stack.split("\n");
|
|
327
|
+
stackList.shift();
|
|
328
|
+
const parentFromStack = stackList.find((line) => !line.includes(__filename));
|
|
329
|
+
if (parentFromStack) {
|
|
330
|
+
const parentFile = parentFromStack.replace(/^.*?\s\(([^\s]+):\d+:\d+\)/, "$1");
|
|
331
|
+
if (parentFile !== parentFromStack) {
|
|
332
|
+
foundPath = true;
|
|
333
|
+
pathUtils.addLocation("app", path.dirname(parentFile));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (!foundPath) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
"The app location cannot be determined. Please specify the appPath option."
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
async _setupConfig() {
|
|
344
|
+
if (this._configReady)
|
|
345
|
+
return;
|
|
346
|
+
this._configReady = true;
|
|
347
|
+
const { config: options } = this._options;
|
|
348
|
+
let configsPath = options.path.replace(/\/$/, "");
|
|
349
|
+
if (options.hasFolder) {
|
|
350
|
+
configsPath = `${configsPath}${path.sep}${options.name}${path.sep}`;
|
|
351
|
+
}
|
|
352
|
+
const filenameFormat = options.filenameFormat.replace(/\[app-name\]/gi, options.name).replace(/\[config-name\]/gi, "[name]");
|
|
353
|
+
const defaultConfigFilename = options.defaultConfigFilename.replace(
|
|
354
|
+
/\[app-name\]/gi,
|
|
355
|
+
options.name
|
|
356
|
+
);
|
|
357
|
+
this.register(
|
|
358
|
+
(0, import_simple_config.simpleConfigProvider)({
|
|
359
|
+
name: options.name,
|
|
360
|
+
defaultConfig: options.default,
|
|
361
|
+
defaultConfigFilename,
|
|
362
|
+
envVarName: options.environmentVariable,
|
|
363
|
+
path: configsPath,
|
|
364
|
+
filenameFormat
|
|
365
|
+
})
|
|
366
|
+
);
|
|
367
|
+
const config = this.getConfig();
|
|
368
|
+
await config.loadFromFile("", true, false);
|
|
369
|
+
if (options.loadFromEnvironment) {
|
|
370
|
+
await config.loadFromEnv();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
_mountResources() {
|
|
374
|
+
this._mountQueue.forEach((mount) => mount(this._express));
|
|
375
|
+
this._mountQueue.length = 0;
|
|
376
|
+
}
|
|
377
|
+
_emitEvent(name, payload) {
|
|
378
|
+
this.eventsHub.emit(name, payload);
|
|
379
|
+
}
|
|
380
|
+
_reduceWithEvent(name, target, payload) {
|
|
381
|
+
return this.eventsHub.reduceSync(name, target, payload);
|
|
382
|
+
}
|
|
383
|
+
async _loadCredentials(credentialsInfo, onHome = true) {
|
|
384
|
+
const location = onHome ? "home" : "app";
|
|
385
|
+
const pathUtils = this.get("pathUtils");
|
|
386
|
+
const keys = ["ca", "cert", "key"];
|
|
387
|
+
const info = await Promise.all(
|
|
388
|
+
keys.map(async (key) => {
|
|
389
|
+
const filepath = credentialsInfo[key];
|
|
390
|
+
if (!filepath)
|
|
391
|
+
return void 0;
|
|
392
|
+
const file = await import_promises.default.readFile(pathUtils.joinFrom(location, filepath), "utf8");
|
|
393
|
+
return {
|
|
394
|
+
key,
|
|
395
|
+
file
|
|
396
|
+
};
|
|
397
|
+
})
|
|
398
|
+
);
|
|
399
|
+
return info.reduce((acc, item) => {
|
|
400
|
+
if (item) {
|
|
401
|
+
acc[item.key] = item.file;
|
|
402
|
+
}
|
|
403
|
+
return acc;
|
|
404
|
+
}, {});
|
|
405
|
+
}
|
|
406
|
+
async _createServer() {
|
|
407
|
+
const [http2Config = {}, httpsConfig = {}] = this.getConfig(["http2", "https"], true);
|
|
408
|
+
if (!http2Config.enabled && !httpsConfig.enabled) {
|
|
409
|
+
return this._express;
|
|
410
|
+
}
|
|
411
|
+
if (http2Config.enabled && !httpsConfig.enabled) {
|
|
412
|
+
throw new Error("HTTP2 requires for HTTPS to be enabled");
|
|
413
|
+
}
|
|
414
|
+
if (!httpsConfig.credentials) {
|
|
415
|
+
throw new Error("The `credentials` object on the HTTPS settings is missing");
|
|
416
|
+
}
|
|
417
|
+
const credentials = await this._loadCredentials(
|
|
418
|
+
httpsConfig.credentials,
|
|
419
|
+
httpsConfig.credentials.onHome
|
|
420
|
+
);
|
|
421
|
+
if (!Object.keys(credentials).length) {
|
|
422
|
+
throw new Error("No credentials were found for HTTPS");
|
|
423
|
+
}
|
|
424
|
+
if (http2Config.enabled) {
|
|
425
|
+
const serverOptions = {
|
|
426
|
+
...credentials,
|
|
427
|
+
spdy: http2Config.spdy
|
|
428
|
+
};
|
|
429
|
+
return (0, import_spdy.createServer)(serverOptions, this._express);
|
|
430
|
+
}
|
|
431
|
+
return (0, import_https.createServer)(credentials, this._express);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const jimpex = (...args) => new Jimpex(...args);
|
|
435
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
436
|
+
0 && (module.exports = {
|
|
437
|
+
Jimpex,
|
|
438
|
+
jimpex
|
|
439
|
+
});
|
|
440
|
+
//# sourceMappingURL=jimpex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/app/jimpex.ts"],"sourcesContent":["import * as path from 'path';\nimport fs from 'fs/promises';\nimport { createServer as createHTTPSServer } from 'https';\nimport { Jimple } from '@homer0/jimple';\nimport { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { appLoggerProvider } from '@homer0/simple-logger';\nimport { envUtilsProvider } from '@homer0/env-utils';\nimport { packageInfoProvider } from '@homer0/package-info';\nimport { pathUtilsProvider } from '@homer0/path-utils';\nimport { rootFileProvider } from '@homer0/root-file';\nimport { EventsHub } from '@homer0/events-hub';\nimport { simpleConfigProvider } from '@homer0/simple-config';\nimport compression from 'compression';\nimport bodyParser from 'body-parser';\nimport multer from 'multer';\nimport {\n createServer as createSpdyServer,\n type ServerOptions as SpdyServerOptions,\n} from 'spdy';\nimport express from 'express';\nimport {\n commonServicesProvider,\n httpServicesProvider,\n utilsServicesProvider,\n} from '../services';\nimport {\n statuses,\n type Controller,\n type ControllerLike,\n type MiddlewareLike,\n type MiddlewareProvider,\n type Middleware,\n} from '../utils';\nimport type {\n DeepPartial,\n Express,\n ExpressMiddlewareLike,\n PathUtils,\n Config,\n Logger,\n JimpexOptions,\n JimpexHTTPSCredentials,\n JimpexHTTP2Options,\n JimpexHTTPSOptions,\n JimpexStartCallback,\n JimpexServer,\n JimpexServerInstance,\n JimpexEventName,\n JimpexEventPayload,\n DeepReadonly,\n JimpexReducerEventName,\n JimpexReducerEventPayload,\n JimpexReducerEventTarget,\n JimpexEventNameLike,\n JimpexEventListener,\n JimpexHealthCheckFn,\n Router,\n} from '../types';\n/**\n * Jimpex is a mix of Jimple, a Javascript port of Pimple dependency injection container,\n * and Express, one of the most popular web frameworks for Node.\n *\n * @group Jimpex\n * @todo Implement `helmet`.\n */\nexport class Jimpex extends Jimple {\n /**\n * The customization settings for the application.\n */\n protected _options: JimpexOptions;\n /**\n * The Express application Jimpex uses under the hood.\n */\n protected _express: Express;\n /**\n * Since the configuration service has an async initialization, the class uses this flag\n * internally to validate if the configuration has been initialized or not.\n */\n protected _configReady: boolean = false;\n /**\n * A reference to the actuall HTTP the application will use. This can vary depending on\n * whether HTTPS, or HTTP2 are enabled. If HTTPS is not enabled, it will be the same as\n * the `express` property; if HTTPS is enabled, it will be an `https` server; and if\n * HTTP2 is enabled, it will be an `spdy` server.\n */\n protected _server?: JimpexServer;\n /**\n * The instance of the server that is listening for requests.\n */\n protected _instance?: JimpexServerInstance;\n /**\n * A list of functions that implement controllers and middlewares. When the application\n * starts, the queue will be processed and those controllers and middlewares will be\n * added to the server instance. The reason they are not added directly like with a\n * regular Express implementation is that services on Jimple use lazy loading, and\n * adding middlewares and controllers as they come could cause errors if they depend on\n * services that are not yet registered.\n */\n protected _mountQueue: Array<(server: Express) => void> = [];\n /**\n * A list with all the top routes controlled by the application. Every time a controller\n * is mounted, its route will be added here.\n */\n protected _controlledRoutes: string[] = [];\n /**\n * @param options Preferences to customize the application.\n * @param config The default settings for the configuration service. It's a\n * shortcuit for `options.config.default`\n */\n constructor(options: DeepPartial<JimpexOptions> = {}, config: unknown = {}) {\n super();\n\n this._options = deepAssignWithOverwrite(\n {\n filesizeLimit: '15MB',\n boot: true,\n path: {\n appPath: '',\n useParentPath: true,\n },\n config: {\n default: options?.config?.default || config,\n name: 'app',\n path: 'config/',\n hasFolder: false,\n loadFromEnvironment: true,\n environmentVariable: 'CONFIG',\n defaultConfigFilename: '[app-name].config.js',\n filenameFormat: '[app-name].[config-name].config.js',\n },\n statics: {\n enabled: true,\n onHome: false,\n route: 'statics',\n },\n express: {\n trustProxy: true,\n disableXPoweredBy: true,\n compression: true,\n bodyParser: true,\n multer: true,\n },\n services: {\n common: true,\n http: true,\n utils: true,\n },\n healthCheck: () => Promise.resolve(true),\n },\n options,\n this._initOptions(),\n );\n\n this._express = express();\n\n this._setupCoreServices();\n this._setupExpress();\n this._configurePath();\n\n this._init();\n if (this._options.boot) {\n this.boot();\n }\n }\n /**\n * This is where the app would register all its specific services, middlewares and controllers.\n */\n boot(): void {}\n /**\n * Disables the server TLS validation. Meant to be used for development purposes.\n */\n disableTLSValidation() {\n // eslint-disable-next-line no-process-env, dot-notation\n process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';\n this.logger.warn('TLS validation has been disabled');\n }\n /**\n * Starts the app server.\n *\n * @param onStart A callback function to be called when the server actually starts.\n * @returns The server instance.\n */\n async start(onStart?: JimpexStartCallback): Promise<JimpexServerInstance> {\n await this._setupConfig();\n const config = this.getConfig();\n const port = config.get<number | undefined>('port');\n if (!port) {\n throw new Error('No port configured');\n }\n this._emitEvent('beforeStart', { app: this });\n this._server = await this._createServer();\n this._instance = this._server!.listen(port, () => {\n this._emitEvent('start', { app: this });\n this._mountResources();\n this.logger.success(`Starting on port ${port}`);\n this._emitEvent('afterStart', { app: this });\n if (onStart) {\n onStart(config);\n }\n this._emitEvent('afterStartCallback', { app: this });\n });\n\n return this._instance!;\n }\n /**\n * This is an alias of `start`. The idea is for it to be used on serverless platforms,\n * where you don't get to start your app, you just have export it.\n *\n * @param port In case the configuration doesn't already have it,\n * this is the port where the application will use to run. If this\n * parameter is used, the method will overwrite the `port`\n * setting on the configuration service.\n * @param onStart A callback function to be called when the server starts.\n * @returns The server instance.\n */\n async listen(\n port?: number,\n onStart?: JimpexStartCallback,\n ): Promise<JimpexServerInstance> {\n if (port) {\n await this._setupConfig();\n const config = this.getConfig();\n config.set('port', port);\n }\n\n return this.start(onStart);\n }\n /**\n * Stops the server instance.\n */\n stop(): void {\n if (!this._instance) return;\n this._emitEvent('beforeStop', { app: this });\n this._instance.close();\n this._instance = undefined;\n this._emitEvent('afterStop', { app: this });\n }\n /**\n * Mounts a route controller or a middleware into a server routes.\n *\n * @param route The route for the controller/middleware.\n * @param controller The controller/middleware resource to be mounted.\n */\n mount(route: string, controller: ControllerLike): void {\n let useController: Controller | Middleware;\n if (\n 'register' in controller &&\n typeof controller.register === 'function' &&\n controller.provider === true\n ) {\n useController = controller.register(this, route);\n } else if (\n 'connect' in controller &&\n typeof controller.connect === 'function' &&\n (('middleware' in controller && controller.middleware === true) ||\n ('controller' in controller && controller.controller === true))\n ) {\n useController = controller;\n } else {\n useController = {\n middleware: true,\n connect: () => controller as ExpressMiddlewareLike,\n };\n }\n\n this._mountQueue.push((server) => {\n const connected = useController.connect(this, route);\n if (!connected) return;\n const router = this._reduceWithEvent('controllerWillBeMounted', connected, {\n route,\n controller: useController,\n app: this,\n });\n server.use(route, router);\n this._emitEvent('routeAdded', { route, app: this });\n this._controlledRoutes.push(route);\n });\n }\n /**\n * Adds a global middleware to the application.\n *\n * @param middleware The middleware resource to be added.\n */\n use(middleware: MiddlewareLike): void {\n const useMiddleware =\n 'register' in middleware && typeof middleware.register === 'function'\n ? (middleware as MiddlewareProvider).register(this)\n : (middleware as Middleware | ExpressMiddlewareLike);\n this._mountQueue.push((server) => {\n if ('connect' in useMiddleware && typeof useMiddleware.connect === 'function') {\n const handler = useMiddleware.connect(this);\n if (handler) {\n server.use(\n this._reduceWithEvent('middlewareWillBeUsed', handler, { app: this }),\n );\n }\n\n return;\n }\n\n server.use(\n this._reduceWithEvent(\n 'middlewareWillBeUsed',\n useMiddleware as ExpressMiddlewareLike,\n { app: this },\n ),\n );\n });\n }\n\n getConfig(): Config;\n getConfig<T = unknown>(setting: string | string[], asArray?: boolean): T;\n /**\n * Gets a setting from the configuration, or the configuration itself.\n *\n * @param setting The setting or settings to be retrieved. If is not specified, it\n * will return the entire configuration.\n * @param asArray If `true` and `setting` is an array, it will return the values as\n * an array instead of an object.\n * @template T The type of the setting to be retrieved.\n */\n getConfig<T = unknown>(\n setting?: string | string[],\n asArray: boolean = false,\n ): Config | T {\n const config = this.try<Config>('config');\n if (!config) {\n throw new Error('The config service is not available until the app starts');\n }\n if (typeof setting === 'undefined') {\n return config;\n }\n\n return config.get<T>(setting, asArray);\n }\n /**\n * Creates a new router instance.\n */\n getRouter(): Router {\n return this.get('router');\n }\n /**\n * The logger service.\n */\n get logger(): Logger {\n return this.get<Logger>('logger');\n }\n /**\n * The Express application Jimpex uses under the hood.\n */\n get express(): Express {\n return this._express;\n }\n /**\n * The server instance that gets created when the app is started.\n */\n get instance(): JimpexServerInstance | undefined {\n return this._instance;\n }\n /**\n * The application customization options.\n */\n get options(): DeepReadonly<JimpexOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n /**\n * Gets the events service.\n */\n get eventsHub(): EventsHub {\n return this.get<EventsHub>('events');\n }\n /**\n * A list of the routes that have controllers mounted on them.\n */\n get routes(): string[] {\n return this._controlledRoutes.slice();\n }\n /**\n * Adds a listener for an application event.\n *\n * @param eventName The name of the event to listen for.\n * @param listener The listener function.\n * @returns A function to unsubscribe the listener.\n * @template EventName The name of the event, to match the type of the listener\n * function.\n */\n on<EventName extends JimpexEventNameLike>(\n eventName: EventName,\n listener: JimpexEventListener<EventName>,\n ): () => boolean {\n return this.eventsHub.on(eventName, listener);\n }\n /**\n * Adds a listener for an application event that will only be execuded once: the first\n * time the event is triggered.\n *\n * @param eventName The name of the event to listen for.\n * @param listener The listener function.\n * @returns A function to unsubscribe the listener.\n * @template EventName The name of the event, to match the type of the listener\n * function.\n */\n once<EventName extends JimpexEventNameLike>(\n eventName: EventName,\n listener: JimpexEventListener<EventName>,\n ): () => boolean {\n return this.eventsHub.once(eventName, listener);\n }\n /**\n * Based on the application options, it returns wheter the application is healthy or\n * not.\n */\n isHealthy(): ReturnType<JimpexHealthCheckFn> {\n return this._options.healthCheck(this);\n }\n /**\n * This method is like a \"lifecycle method\", it gets executed on the constructor right\n * before the \"boot step\". The idea is for the method to be a helper when the\n * application is defined by subclassing {@link Jimpex}: the application could register\n * all important services here and the routes on boot, then, if the implementation needs\n * to access or overwrite a something, it can send `boot: false`, access/register what\n * it needs, and then call `boot()`. That would be impossible for an application without\n * overwriting the constructor and the boot functionality.\n */\n protected _init(): void {}\n /**\n * It generates overwrites for the application options when it gets created. This method\n * is a helper for when the application is defined by subclassing {@link Jimpex}: It's\n * highly probable that if the application needs to change the default options, it would\n * want to do it right from the class, instead of having to do it on every\n * implementation. A way to do it would be overwriting the constructor and calling\n * `super` with the custom overwrites, but this method exists so that won't be\n * necessary: when creating the `options`, the constructor will merge the result of this\n * method on top of the default ones.\n */\n protected _initOptions(): DeepPartial<JimpexOptions> {\n return {};\n }\n /**\n * Registers the \"core services\" on the container: logger, events, utils, etc.\n */\n protected _setupCoreServices(): void {\n this.register(\n appLoggerProvider({\n serviceName: 'logger',\n }),\n );\n this.register(envUtilsProvider);\n this.register(packageInfoProvider);\n this.register(pathUtilsProvider);\n this.register(rootFileProvider);\n const { services: enabledServices } = this._options;\n if (enabledServices.common) this.register(commonServicesProvider);\n if (enabledServices.http) this.register(httpServicesProvider);\n if (enabledServices.utils) this.register(utilsServicesProvider);\n\n this.set('events', () => new EventsHub());\n this.set('statuses', () => statuses);\n }\n /**\n * Configures the Express application based on the class options.\n */\n protected _setupExpress(): void {\n const { statics, filesizeLimit, express: expressOptions } = this._options;\n if (expressOptions.trustProxy) {\n this._express.enable('trust proxy');\n }\n\n if (expressOptions.disableXPoweredBy) {\n this._express.disable('x-powered-by');\n }\n\n if (expressOptions.compression) {\n this._express.use(compression());\n }\n\n if (statics.enabled) {\n this._addStaticsFolder(statics.route, statics.folder, statics.onHome);\n }\n\n if (expressOptions.bodyParser) {\n this._express.use(\n bodyParser.json({\n limit: filesizeLimit,\n }),\n );\n this._express.use(\n bodyParser.urlencoded({\n extended: true,\n limit: filesizeLimit,\n }),\n );\n }\n\n if (expressOptions.multer) {\n this._express.use(multer().any());\n }\n\n this.set(\n 'router',\n this.factory(() => express.Router()),\n );\n }\n /**\n * Adds a static folder to the application.\n *\n * @param route The route to add the folder to.\n * @param folder The path to the folder in the file system. If not defined, it will\n * be use the same value as `route`. The path could be relative to the\n * project root, or where the application executable is located,\n * depending on the value of the `onHome` parameter.\n * @param onHome If `true`, the path to the folder will be relative to the project\n * root. If `false`, it will be relative to where the application\n * executable is located.\n */\n protected _addStaticsFolder(\n route: string,\n folder: string = '',\n onHome: boolean = false,\n ) {\n const location = onHome ? 'home' : 'app';\n const staticRoute = route.replace(/^\\/+/, '');\n const pathUtils = this.get<PathUtils>('pathUtils');\n const staticFolder = pathUtils.joinFrom(location, folder || staticRoute);\n this.mount(`/${staticRoute}`, {\n connect: () => express.static(staticFolder),\n controller: true,\n });\n }\n /**\n * This helper method validates the `path` options in order to register the `app`\n * location in the `pathUtils` service. The `app` location should be the path to where\n * the application executable is located, but due to how ESM works, we can't infer it\n * from the `module` object, so we need either recieved as the `appPath` setting, or try\n * to get it from the parent module.\n *\n * @throws If the method should use the path from the parent module, but can't find\n * it.\n */\n protected _configurePath(): void {\n const pathUtils = this.get<PathUtils>('pathUtils');\n const {\n path: { appPath, useParentPath },\n } = this._options;\n if (appPath) {\n pathUtils.addLocation('app', appPath);\n return;\n }\n let foundPath = false;\n if (useParentPath) {\n const stack = new Error().stack!;\n const stackList = stack.split('\\n');\n stackList.shift();\n const parentFromStack = stackList.find((line) => !line.includes(__filename));\n if (parentFromStack) {\n const parentFile = parentFromStack.replace(/^.*?\\s\\(([^\\s]+):\\d+:\\d+\\)/, '$1');\n if (parentFile !== parentFromStack) {\n foundPath = true;\n pathUtils.addLocation('app', path.dirname(parentFile));\n }\n }\n }\n\n if (!foundPath) {\n throw new Error(\n 'The app location cannot be determined. Please specify the appPath option.',\n );\n }\n }\n /**\n * Setups the configuration service. The new configuration service requires async calls\n * in order to load the configuration files (as it uses `import` instead of `require`),\n * so it can't be instantiated as the other services.\n * This method is called just before starting the application.\n */\n protected async _setupConfig(): Promise<void> {\n if (this._configReady) return;\n this._configReady = true;\n const { config: options } = this._options;\n\n let configsPath = options.path.replace(/\\/$/, '');\n if (options.hasFolder) {\n configsPath = `${configsPath}${path.sep}${options.name}${path.sep}`;\n }\n\n const filenameFormat = options.filenameFormat\n .replace(/\\[app-name\\]/gi, options.name)\n .replace(/\\[config-name\\]/gi, '[name]');\n const defaultConfigFilename = options.defaultConfigFilename.replace(\n /\\[app-name\\]/gi,\n options.name,\n );\n\n this.register(\n simpleConfigProvider({\n name: options.name,\n defaultConfig: options.default,\n defaultConfigFilename,\n envVarName: options.environmentVariable,\n path: configsPath,\n filenameFormat,\n }),\n );\n\n const config = this.getConfig();\n await config.loadFromFile('', true, false);\n if (options.loadFromEnvironment) {\n await config.loadFromEnv();\n }\n }\n /**\n * Processes the resources from the mount queue (added with {@link Jimpex.mount} and\n * {@link Jimpex.use}), and adds them to the Express application.\n */\n protected _mountResources(): void {\n this._mountQueue.forEach((mount) => mount(this._express));\n this._mountQueue.length = 0;\n }\n /**\n * Emits an event using the `events` service.\n *\n * @param name The name of the event to emit.\n * @param payload The event payload.\n * @template EventName The literal name of the event, to type the event payload.\n */\n protected _emitEvent<EventName extends JimpexEventName>(\n name: EventName,\n payload: JimpexEventPayload<EventName>,\n ): void {\n this.eventsHub.emit(name, payload);\n }\n /**\n * Sends a target object to a list of reducer events so they can modify or replace it.\n *\n * @param name The name of the event to use.\n * @param target The object to reduce with the event.\n * @param payload Extra context for the listeners.\n */\n protected _reduceWithEvent<EventName extends JimpexReducerEventName>(\n name: EventName,\n target: JimpexReducerEventTarget<EventName>,\n payload: JimpexReducerEventPayload<EventName>,\n ): JimpexReducerEventTarget<EventName> {\n return this.eventsHub.reduceSync(name, target, payload);\n }\n /**\n * Loads the contents of a dictionary of credentials files that need to be used to\n * configure HTTPS.\n *\n * @param credentialsInfo The dictionary where the keys are the type of credentials\n * (`ca`, `cert`, `key`) and the values are the paths to the\n * files.\n * @param onHome If this is `true`, the path of the files will be relative\n * to the project root. If it is `false`, it will be relative\n * to where the application executable is located.\n * @returns\n */\n protected async _loadCredentials(\n credentialsInfo: JimpexHTTPSCredentials,\n onHome: boolean = true,\n ): Promise<JimpexHTTPSCredentials> {\n const location = onHome ? 'home' : 'app';\n const pathUtils = this.get<PathUtils>('pathUtils');\n const keys: Array<keyof JimpexHTTPSCredentials> = ['ca', 'cert', 'key'];\n const info = await Promise.all(\n keys.map(async (key) => {\n const filepath = credentialsInfo[key];\n if (!filepath) return undefined;\n const file = await fs.readFile(pathUtils.joinFrom(location, filepath), 'utf8');\n return {\n key,\n file,\n };\n }),\n );\n\n return info.reduce<JimpexHTTPSCredentials>((acc, item) => {\n if (item) {\n acc[item.key] = item.file;\n }\n\n return acc;\n }, {});\n }\n /**\n * Validates the configuration and chooses the server the application needs to use: If\n * HTTP2 is enabled, it will use Spdy; if HTTPS is enabled but HTTP is not, it will use\n * the native HTTPS server; otherwise, it will be just the Express instance.\n *\n * @returns {Server}\n * @throws {Error} If HTTP2 is enabled but HTTPS is not.\n * @throws {Error} If HTTPS is enabled but there's no `https.credentials` object.\n * @throws {Error} If HTTPS is enabled and no creadentials are found.\n * @access protected\n * @ignore\n */\n protected async _createServer(): Promise<JimpexServer> {\n const [http2Config = {}, httpsConfig = {}] = this.getConfig<\n [JimpexHTTP2Options, JimpexHTTPSOptions]\n >(['http2', 'https'], true);\n\n if (!http2Config.enabled && !httpsConfig.enabled) {\n return this._express;\n }\n\n if (http2Config.enabled && !httpsConfig.enabled) {\n throw new Error('HTTP2 requires for HTTPS to be enabled');\n }\n\n if (!httpsConfig.credentials) {\n throw new Error('The `credentials` object on the HTTPS settings is missing');\n }\n\n const credentials = await this._loadCredentials(\n httpsConfig.credentials,\n httpsConfig.credentials.onHome,\n );\n\n if (!Object.keys(credentials).length) {\n throw new Error('No credentials were found for HTTPS');\n }\n\n if (http2Config.enabled) {\n const serverOptions: SpdyServerOptions = {\n ...credentials,\n spdy: http2Config.spdy,\n };\n\n return createSpdyServer(serverOptions, this._express);\n }\n\n return createHTTPSServer(credentials, this._express);\n }\n}\n/**\n * Shorthand for `new Jimpex()`.\n *\n * @param args The same parameters as the {@link Jimpex} constructor.\n * @returns A new instance of {@link Jimpex}.\n * @group Jimpex\n */\nexport const jimpex = (...args: ConstructorParameters<typeof Jimpex>): Jimpex =>\n new Jimpex(...args);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,sBAAe;AACf,mBAAkD;AAClD,oBAAuB;AACvB,yBAAwC;AACxC,2BAAkC;AAClC,uBAAiC;AACjC,0BAAoC;AACpC,wBAAkC;AAClC,uBAAiC;AACjC,wBAA0B;AAC1B,2BAAqC;AACrC,yBAAwB;AACxB,yBAAuB;AACvB,oBAAmB;AACnB,kBAGO;AACP,qBAAoB;AACpB,sBAIO;AACP,mBAOO;AAiCA,MAAM,eAAe,qBAAO;AAAA,EA4CjC,YAAY,UAAsC,CAAC,GAAG,SAAkB,CAAC,GAAG;AAC1E,UAAM;AAzCR,wBAAU;AAIV,wBAAU;AAKV,wBAAU,gBAAwB;AAOlC,wBAAU;AAIV,wBAAU;AASV,wBAAU,eAAgD,CAAC;AAK3D,wBAAU,qBAA8B,CAAC;AASvC,SAAK,eAAW;AAAA,MACd;AAAA,QACE,eAAe;AAAA,QACf,MAAM;AAAA,QACN,MAAM;AAAA,UACJ,SAAS;AAAA,UACT,eAAe;AAAA,QACjB;AAAA,QACA,QAAQ;AAAA,UACN,SAAS,SAAS,QAAQ,WAAW;AAAA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AY,SAAS;AACvB,YAAM,gBAAmC;AAAA,QACvC,GAAG;AAAA,QACH,MAAM,YAAY;AAAA,MACpB;AAEA,iBAAO,YAAAC,cAAiB,eAAe,KAAK,QAAQ;AAAA,IACtD;AAEA,eAAO,aAAAC,cAAkB,aAAa,KAAK,QAAQ;AAAA,EACrD;AACF;AAQO,MAAM,SAAS,IAAI,SACxB,IAAI,OAAO,GAAG,IAAI;","names":["express","compression","bodyParser","multer","fs","createSpdyServer","createHTTPSServer"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { C as ControllerConnectFn } from '../../jimpex-7eaee271.js';
|
|
3
|
+
import { ExpressMiddleware, AsyncExpressMiddleware } from '../../types/express.js';
|
|
4
|
+
import { SimpleConfig } from '@homer0/simple-config';
|
|
5
|
+
import { ResponsesBuilder } from '../../services/http/responsesBuilder.js';
|
|
6
|
+
import { Response } from 'express';
|
|
7
|
+
import '@homer0/events-hub';
|
|
8
|
+
import '../../types/http.js';
|
|
9
|
+
import 'https';
|
|
10
|
+
import 'http';
|
|
11
|
+
import 'spdy';
|
|
12
|
+
import 'node-fetch';
|
|
13
|
+
import '../../types/utils.js';
|
|
14
|
+
import '@homer0/simple-logger';
|
|
15
|
+
import '../../utils/fns/statuses.js';
|
|
16
|
+
import 'statuses';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The options to contruct a {@link ConfigController}.
|
|
20
|
+
*
|
|
21
|
+
* @group Controllers/Config
|
|
22
|
+
*/
|
|
23
|
+
type ConfigControllerOptions = {
|
|
24
|
+
/**
|
|
25
|
+
* A dictionary with the dependencies to inject.
|
|
26
|
+
*/
|
|
27
|
+
inject: {
|
|
28
|
+
responsesBuilder: ResponsesBuilder;
|
|
29
|
+
config: SimpleConfig;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The controller class that allows to show and switch the application configuration.
|
|
34
|
+
*
|
|
35
|
+
* @group Controller Classes
|
|
36
|
+
* @group Controllers/Config
|
|
37
|
+
* @prettierignore
|
|
38
|
+
*/
|
|
39
|
+
declare class ConfigController {
|
|
40
|
+
/**
|
|
41
|
+
* The service in charge or building the responses.
|
|
42
|
+
*/
|
|
43
|
+
protected readonly _responsesBuilder: ResponsesBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* The service in charge of the configuration.
|
|
46
|
+
*/
|
|
47
|
+
protected readonly _config: SimpleConfig;
|
|
48
|
+
/**
|
|
49
|
+
* @param options The options to construct the controller.
|
|
50
|
+
*/
|
|
51
|
+
constructor({ inject }: ConfigControllerOptions);
|
|
52
|
+
/**
|
|
53
|
+
* Creates the middleware the shows the current configuration.
|
|
54
|
+
*/
|
|
55
|
+
showConfig(): ExpressMiddleware;
|
|
56
|
+
/**
|
|
57
|
+
* Creates the middleware the allows to switch the configuration.
|
|
58
|
+
*/
|
|
59
|
+
switchConfig(): AsyncExpressMiddleware;
|
|
60
|
+
/**
|
|
61
|
+
* Utility to respond with the current configuration.
|
|
62
|
+
*/
|
|
63
|
+
protected respondWithConfig(res: Response): void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* This controller is kind of special as it will only mount the routes if the
|
|
67
|
+
* `debug.configController` setting of the app configuration is set to `true`.
|
|
68
|
+
*
|
|
69
|
+
* It provides routes for:
|
|
70
|
+
* - `/`: Showing the current configuration.
|
|
71
|
+
* - `/switch/:name`: Switching the configuration, but only if the service allows it.
|
|
72
|
+
*
|
|
73
|
+
* @group Controllers
|
|
74
|
+
* @group Controllers/Config
|
|
75
|
+
*/
|
|
76
|
+
declare const configController: _homer0_jimple.Resource<"controller", "connect", ControllerConnectFn>;
|
|
77
|
+
|
|
78
|
+
export { ConfigController, ConfigControllerOptions, configController };
|