jimpex 7.0.2 → 9.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 +93 -0
- package/LICENSE +1 -1
- package/README.md +447 -435
- package/dist/app/index.d.mts +14 -0
- package/dist/app/index.d.ts +14 -0
- package/dist/app/index.js +23 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/jimpex.d.mts +14 -0
- package/dist/app/jimpex.d.ts +14 -0
- package/dist/app/jimpex.js +665 -0
- package/dist/app/jimpex.js.map +1 -0
- package/dist/controllers/common/config.d.mts +79 -0
- package/dist/controllers/common/config.d.ts +79 -0
- package/dist/controllers/common/config.js +107 -0
- package/dist/controllers/common/config.js.map +1 -0
- package/dist/controllers/common/health.d.mts +83 -0
- package/dist/controllers/common/health.d.ts +83 -0
- package/dist/controllers/common/health.js +115 -0
- package/dist/controllers/common/health.js.map +1 -0
- package/dist/controllers/common/index.d.mts +21 -0
- package/dist/controllers/common/index.d.ts +21 -0
- package/dist/controllers/common/index.js +27 -0
- package/dist/controllers/common/index.js.map +1 -0
- package/dist/controllers/common/statics.d.mts +215 -0
- package/dist/controllers/common/statics.d.ts +215 -0
- package/dist/controllers/common/statics.js +253 -0
- package/dist/controllers/common/statics.js.map +1 -0
- package/dist/controllers/index.d.mts +24 -0
- package/dist/controllers/index.d.ts +24 -0
- package/dist/controllers/index.js +25 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/utils/gateway.d.mts +725 -0
- package/dist/controllers/utils/gateway.d.ts +725 -0
- package/dist/controllers/utils/gateway.js +577 -0
- package/dist/controllers/utils/gateway.js.map +1 -0
- package/dist/controllers/utils/index.d.mts +17 -0
- package/dist/controllers/utils/index.d.ts +17 -0
- package/dist/controllers/utils/index.js +23 -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 +636 -0
- package/dist/esm/app/jimpex.js.map +1 -0
- package/dist/esm/chunk-2B2CG5KL.js +11 -0
- package/dist/esm/chunk-2B2CG5KL.js.map +1 -0
- package/dist/esm/controllers/common/config.js +80 -0
- package/dist/esm/controllers/common/config.js.map +1 -0
- package/dist/esm/controllers/common/health.js +88 -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 +220 -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 +556 -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 +116 -0
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
- package/dist/esm/middlewares/common/forceHTTPS.js +53 -0
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/esm/middlewares/common/hsts.js +74 -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 +158 -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 +100 -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 +135 -0
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/esm/services/common/appError.js +98 -0
- package/dist/esm/services/common/appError.js.map +1 -0
- package/dist/esm/services/common/httpError.js +28 -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 +66 -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 +194 -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 +97 -0
- package/dist/esm/services/http/apiClient.js.map +1 -0
- package/dist/esm/services/http/http.js +174 -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 +152 -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 +94 -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-b2a04c78.d.ts +1282 -0
- package/dist/index-efeb437e.d.ts +1282 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/common/errorHandler.d.mts +132 -0
- package/dist/middlewares/common/errorHandler.d.ts +132 -0
- package/dist/middlewares/common/errorHandler.js +143 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -0
- package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +69 -0
- package/dist/middlewares/common/forceHTTPS.js +80 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/middlewares/common/hsts.d.mts +110 -0
- package/dist/middlewares/common/hsts.d.ts +110 -0
- package/dist/middlewares/common/hsts.js +101 -0
- package/dist/middlewares/common/hsts.js.map +1 -0
- package/dist/middlewares/common/index.d.mts +22 -0
- package/dist/middlewares/common/index.d.ts +22 -0
- package/dist/middlewares/common/index.js +27 -0
- package/dist/middlewares/common/index.js.map +1 -0
- package/dist/middlewares/html/fastHTML.d.mts +180 -0
- package/dist/middlewares/html/fastHTML.d.ts +180 -0
- package/dist/middlewares/html/fastHTML.js +185 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -0
- package/dist/middlewares/html/index.d.mts +21 -0
- package/dist/middlewares/html/index.d.ts +21 -0
- package/dist/middlewares/html/index.js +25 -0
- package/dist/middlewares/html/index.js.map +1 -0
- package/dist/middlewares/html/showHTML.d.mts +127 -0
- package/dist/middlewares/html/showHTML.d.ts +127 -0
- package/dist/middlewares/html/showHTML.js +127 -0
- package/dist/middlewares/html/showHTML.js.map +1 -0
- package/dist/middlewares/index.d.mts +30 -0
- package/dist/middlewares/index.d.ts +30 -0
- package/dist/middlewares/index.js +27 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/utils/index.d.mts +20 -0
- package/dist/middlewares/utils/index.d.ts +20 -0
- package/dist/middlewares/utils/index.js +23 -0
- package/dist/middlewares/utils/index.js.map +1 -0
- package/dist/middlewares/utils/versionValidator.d.mts +215 -0
- package/dist/middlewares/utils/versionValidator.d.ts +215 -0
- package/dist/middlewares/utils/versionValidator.js +162 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/services/common/appError.d.mts +139 -0
- package/dist/services/common/appError.d.ts +139 -0
- package/dist/services/common/appError.js +126 -0
- package/dist/services/common/appError.js.map +1 -0
- package/dist/services/common/httpError.d.mts +80 -0
- package/dist/services/common/httpError.d.ts +80 -0
- package/dist/services/common/httpError.js +53 -0
- package/dist/services/common/httpError.js.map +1 -0
- package/dist/services/common/index.d.mts +47 -0
- package/dist/services/common/index.d.ts +47 -0
- package/dist/services/common/index.js +44 -0
- package/dist/services/common/index.js.map +1 -0
- package/dist/services/common/sendFile.d.mts +102 -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.mts +96 -0
- package/dist/services/frontend/frontendFs.d.ts +96 -0
- package/dist/services/frontend/frontendFs.js +103 -0
- package/dist/services/frontend/frontendFs.js.map +1 -0
- package/dist/services/frontend/index.d.mts +40 -0
- package/dist/services/frontend/index.d.ts +40 -0
- package/dist/services/frontend/index.js +36 -0
- package/dist/services/frontend/index.js.map +1 -0
- package/dist/services/html/htmlGenerator.d.mts +237 -0
- package/dist/services/html/htmlGenerator.d.ts +237 -0
- package/dist/services/html/htmlGenerator.js +221 -0
- package/dist/services/html/htmlGenerator.js.map +1 -0
- package/dist/services/html/index.d.mts +43 -0
- package/dist/services/html/index.d.ts +43 -0
- package/dist/services/html/index.js +36 -0
- package/dist/services/html/index.js.map +1 -0
- package/dist/services/http/apiClient.d.mts +170 -0
- package/dist/services/http/apiClient.d.ts +170 -0
- package/dist/services/http/apiClient.js +122 -0
- package/dist/services/http/apiClient.js.map +1 -0
- package/dist/services/http/http.d.mts +176 -0
- package/dist/services/http/http.d.ts +176 -0
- package/dist/services/http/http.js +211 -0
- package/dist/services/http/http.js.map +1 -0
- package/dist/services/http/index.d.mts +51 -0
- package/dist/services/http/index.d.ts +51 -0
- package/dist/services/http/index.js +44 -0
- package/dist/services/http/index.js.map +1 -0
- package/dist/services/http/responsesBuilder.d.mts +179 -0
- package/dist/services/http/responsesBuilder.d.ts +179 -0
- package/dist/services/http/responsesBuilder.js +179 -0
- package/dist/services/http/responsesBuilder.js.map +1 -0
- package/dist/services/index.d.mts +33 -0
- package/dist/services/index.d.ts +33 -0
- package/dist/services/index.js +31 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/utils/ensureBearerToken.d.mts +158 -0
- package/dist/services/utils/ensureBearerToken.d.ts +158 -0
- package/dist/services/utils/ensureBearerToken.js +121 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/services/utils/index.d.mts +44 -0
- package/dist/services/utils/index.d.ts +44 -0
- package/dist/services/utils/index.js +36 -0
- package/dist/services/utils/index.js.map +1 -0
- package/dist/types/events.d.mts +14 -0
- package/dist/types/events.d.ts +14 -0
- package/dist/types/events.js +17 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/express.d.mts +10 -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.mts +79 -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.mts +14 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +33 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.mts +14 -0
- package/dist/types/options.d.ts +14 -0
- package/dist/types/options.js +17 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/utils.d.mts +48 -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.mts +4 -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.mts +5 -0
- package/dist/utils/fns/index.d.ts +5 -0
- package/dist/utils/fns/index.js +29 -0
- package/dist/utils/fns/index.js.map +1 -0
- package/dist/utils/fns/others.d.mts +17 -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.mts +39 -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.mts +45 -0
- package/dist/utils/fns/statuses.d.ts +45 -0
- package/dist/utils/fns/statuses.js +39 -0
- package/dist/utils/fns/statuses.js.map +1 -0
- package/dist/utils/fns/text.d.mts +9 -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.mts +19 -0
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.js +25 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/wrappers.d.mts +14 -0
- package/dist/utils/wrappers.d.ts +14 -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 +60 -39
- 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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './app';\nexport * from './types';\nexport * from './controllers';\nexport * from './middlewares';\nexport * from './services';\nexport * from './utils';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "../../chunk-2B2CG5KL.js";
|
|
4
|
+
import { deepAssignWithOverwrite } from "@homer0/deep-assign";
|
|
5
|
+
import { middlewareCreator } from "../../utils";
|
|
6
|
+
import { AppError } from "../../services";
|
|
7
|
+
class ErrorHandler {
|
|
8
|
+
/**
|
|
9
|
+
* @param options The options to construct the class.
|
|
10
|
+
*/
|
|
11
|
+
constructor({
|
|
12
|
+
inject: { logger, responsesBuilder, statuses, HTTPError },
|
|
13
|
+
...options
|
|
14
|
+
}) {
|
|
15
|
+
/**
|
|
16
|
+
* The service that will log the messages in the console.
|
|
17
|
+
*/
|
|
18
|
+
__publicField(this, "_logger");
|
|
19
|
+
/**
|
|
20
|
+
* The service to generate the responses.
|
|
21
|
+
*/
|
|
22
|
+
__publicField(this, "_responsesBuilder");
|
|
23
|
+
/**
|
|
24
|
+
* The uility service to get HTTP status codes.
|
|
25
|
+
*/
|
|
26
|
+
__publicField(this, "_statuses");
|
|
27
|
+
/**
|
|
28
|
+
* The Error class used by the "known errors".
|
|
29
|
+
*/
|
|
30
|
+
__publicField(this, "_HTTPError");
|
|
31
|
+
/**
|
|
32
|
+
* The customization options.
|
|
33
|
+
*/
|
|
34
|
+
__publicField(this, "_options");
|
|
35
|
+
this._logger = logger;
|
|
36
|
+
this._responsesBuilder = responsesBuilder;
|
|
37
|
+
this._statuses = statuses;
|
|
38
|
+
this._HTTPError = HTTPError;
|
|
39
|
+
this._options = deepAssignWithOverwrite(
|
|
40
|
+
{
|
|
41
|
+
showErrors: false,
|
|
42
|
+
response: {
|
|
43
|
+
message: "Unexpected error",
|
|
44
|
+
status: this._statuses("internal server error")
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
options
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Generates the middleware that handles the errors.
|
|
52
|
+
*/
|
|
53
|
+
getMiddleware() {
|
|
54
|
+
return (err, _, res, next) => {
|
|
55
|
+
if (!err) {
|
|
56
|
+
next();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const { response, showErrors } = this._options;
|
|
60
|
+
let { status } = response;
|
|
61
|
+
let data = {
|
|
62
|
+
error: true,
|
|
63
|
+
message: response.message
|
|
64
|
+
};
|
|
65
|
+
const knownError = err instanceof AppError;
|
|
66
|
+
if (showErrors || knownError) {
|
|
67
|
+
data.message = err.message;
|
|
68
|
+
if (knownError) {
|
|
69
|
+
data = {
|
|
70
|
+
...data,
|
|
71
|
+
...err.getResponse()
|
|
72
|
+
};
|
|
73
|
+
status = err.status || this._statuses("bad request");
|
|
74
|
+
}
|
|
75
|
+
if (showErrors && err instanceof Error && err.stack) {
|
|
76
|
+
const stack = err.stack.split("\n").map((line) => line.trim());
|
|
77
|
+
data.stack = stack;
|
|
78
|
+
stack.splice(0, 1);
|
|
79
|
+
this._logger.error(`ERROR: ${err.message}`);
|
|
80
|
+
this._logger.info(stack);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this._responsesBuilder.json({
|
|
84
|
+
res,
|
|
85
|
+
data,
|
|
86
|
+
status
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The handler customization options.
|
|
92
|
+
*/
|
|
93
|
+
get options() {
|
|
94
|
+
return deepAssignWithOverwrite({}, this._options);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const errorHandlerMiddleware = middlewareCreator(
|
|
98
|
+
(options = {}) => (app) => {
|
|
99
|
+
const showErrors = app.getConfig("debug.showErrors") === true;
|
|
100
|
+
return new ErrorHandler({
|
|
101
|
+
inject: {
|
|
102
|
+
logger: app.get("logger"),
|
|
103
|
+
responsesBuilder: app.get("responsesBuilder"),
|
|
104
|
+
statuses: app.get("statuses"),
|
|
105
|
+
HTTPError: app.get("HTTPError")
|
|
106
|
+
},
|
|
107
|
+
showErrors,
|
|
108
|
+
...options
|
|
109
|
+
}).getMiddleware();
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
export {
|
|
113
|
+
ErrorHandler,
|
|
114
|
+
errorHandlerMiddleware
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=errorHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/middlewares/common/errorHandler.ts"],"sourcesContent":["import { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { middlewareCreator, type Statuses } from '../../utils';\nimport type { DeepPartial, Logger, ExpressErrorHandler } from '../../types';\nimport { AppError, type HTTPErrorClass, type ResponsesBuilder } from '../../services';\n/**\n * The options for the responses the middleware will create.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerResponseOptions = {\n /**\n * The message to show in case `showErrors` is set to `false`.\n *\n * @default 'Oops! Something went wrong, please try again'\n * @prettierignore\n */\n message: string;\n /**\n * The default status code for the responses.\n *\n * @default 500\n */\n status: number;\n};\n/**\n * The customization options for the middleware.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerOptions = {\n /**\n * If `false`, unknown errors will show a generic message instead of real message. And\n * if `true`, it will not only show all kind of errors but it will also show the error\n * stack.\n *\n * By \"uknown errors\", it means that are not `AppError` nor `HTTPError`.\n */\n showErrors: boolean;\n /**\n * The options for the default response the middleware will create.\n */\n response: ErrorHandlerResponseOptions;\n};\n/**\n * A partial version of the {@link ErrorHandlerOptions}, to be used in the constructor and\n * the middleware creator.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerPartialOptions = DeepPartial<ErrorHandlerOptions>;\n/**\n * The options to construct a {@link ErrorHandler}.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerConstructorOptions = ErrorHandlerPartialOptions & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n logger: Logger;\n responsesBuilder: ResponsesBuilder;\n statuses: Statuses;\n HTTPError: HTTPErrorClass;\n };\n};\n/**\n * Creates a middleware that handles errors and generates the responses.\n *\n * @group Middleware Classes\n * @group Middlewares/ErrorHandler\n * @prettierignore\n */\nexport class ErrorHandler {\n /**\n * The service that will log the messages in the console.\n */\n protected readonly _logger: Logger;\n /**\n * The service to generate the responses.\n */\n protected readonly _responsesBuilder: ResponsesBuilder;\n /**\n * The uility service to get HTTP status codes.\n */\n protected readonly _statuses: Statuses;\n /**\n * The Error class used by the \"known errors\".\n */\n protected readonly _HTTPError: HTTPErrorClass;\n /**\n * The customization options.\n */\n protected readonly _options: ErrorHandlerOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor({\n inject: { logger, responsesBuilder, statuses, HTTPError },\n ...options\n }: ErrorHandlerConstructorOptions) {\n this._logger = logger;\n this._responsesBuilder = responsesBuilder;\n this._statuses = statuses;\n this._HTTPError = HTTPError;\n this._options = deepAssignWithOverwrite(\n {\n showErrors: false,\n response: {\n message: 'Unexpected error',\n status: this._statuses('internal server error'),\n },\n },\n options,\n );\n }\n /**\n * Generates the middleware that handles the errors.\n */\n getMiddleware(): ExpressErrorHandler {\n return (err, _, res, next) => {\n // If there wasn't any error, continue the execution.\n if (!err) {\n next();\n return;\n }\n\n const { response, showErrors } = this._options;\n\n // Define the base status and response.\n let { status } = response;\n let data: {\n error: boolean;\n message: string;\n stack?: string[];\n } & Record<string, unknown> = {\n error: true,\n message: response.message,\n };\n\n const knownError = err instanceof AppError;\n // If it's a \"known error\" or the `showErrors` flag is set to `true`...\n if (showErrors || knownError) {\n // Get the real message.\n data.message = err.message;\n // If it's a \"known error\"...\n if (knownError) {\n // Try to extract information for the response.\n data = {\n ...data,\n ...err.getResponse(),\n };\n status = err.status || (this._statuses('bad request') as number);\n }\n /**\n * If the flag is set to `true`, and it's a \"valid error\", try to extract the\n * stack, format it, and include it in the response.\n */\n if (showErrors && err instanceof Error && err.stack) {\n const stack = err.stack.split('\\n').map((line) => line.trim());\n data.stack = stack;\n stack.splice(0, 1);\n this._logger.error(`ERROR: ${err.message}`);\n this._logger.info(stack);\n }\n }\n\n this._responsesBuilder.json({\n res,\n data,\n status,\n });\n };\n }\n /**\n * The handler customization options.\n */\n get options(): Readonly<ErrorHandlerOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n}\n/**\n * Creates the middleware that handles errors.\n *\n * @group Middlewares\n * @group Middlewares/ErrorHandler\n */\nexport const errorHandlerMiddleware = middlewareCreator(\n (options: ErrorHandlerPartialOptions = {}) =>\n (app) => {\n const showErrors = app.getConfig<boolean | undefined>('debug.showErrors') === true;\n return new ErrorHandler({\n inject: {\n logger: app.get('logger'),\n responsesBuilder: app.get('responsesBuilder'),\n statuses: app.get('statuses'),\n HTTPError: app.get('HTTPError'),\n },\n showErrors,\n ...options,\n }).getMiddleware();\n },\n);\n"],"mappings":";;;AAAA,SAAS,+BAA+B;AACxC,SAAS,yBAAwC;AAEjD,SAAS,gBAA4D;AAsE9D,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA,EAwBxB,YAAY;AAAA,IACV,QAAQ,EAAE,QAAQ,kBAAkB,UAAU,UAAU;AAAA,IACxD,GAAG;AAAA,EACL,GAAmC;AAvBnC;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAQjB,SAAK,UAAU;AACf,SAAK,oBAAoB;AACzB,SAAK,YAAY;AACjB,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,MACd;AAAA,QACE,YAAY;AAAA,QACZ,UAAU;AAAA,UACR,SAAS;AAAA,UACT,QAAQ,KAAK,UAAU,uBAAuB;AAAA,QAChD;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAqC;AACnC,WAAO,CAAC,KAAK,GAAG,KAAK,SAAS;AAE5B,UAAI,CAAC,KAAK;AACR,aAAK;AACL;AAAA,MACF;AAEA,YAAM,EAAE,UAAU,WAAW,IAAI,KAAK;AAGtC,UAAI,EAAE,OAAO,IAAI;AACjB,UAAI,OAI0B;AAAA,QAC5B,OAAO;AAAA,QACP,SAAS,SAAS;AAAA,MACpB;AAEA,YAAM,aAAa,eAAe;AAElC,UAAI,cAAc,YAAY;AAE5B,aAAK,UAAU,IAAI;AAEnB,YAAI,YAAY;AAEd,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,GAAG,IAAI,YAAY;AAAA,UACrB;AACA,mBAAS,IAAI,UAAW,KAAK,UAAU,aAAa;AAAA,QACtD;AAKA,YAAI,cAAc,eAAe,SAAS,IAAI,OAAO;AACnD,gBAAM,QAAQ,IAAI,MAAM,MAAM,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC;AAC7D,eAAK,QAAQ;AACb,gBAAM,OAAO,GAAG,CAAC;AACjB,eAAK,QAAQ,MAAM,UAAU,IAAI,OAAO,EAAE;AAC1C,eAAK,QAAQ,KAAK,KAAK;AAAA,QACzB;AAAA,MACF;AAEA,WAAK,kBAAkB,KAAK;AAAA,QAC1B;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAyC;AAC3C,WAAO,wBAAwB,CAAC,GAAG,KAAK,QAAQ;AAAA,EAClD;AACF;AAOO,MAAM,yBAAyB;AAAA,EACpC,CAAC,UAAsC,CAAC,MACtC,CAAC,QAAQ;AACP,UAAM,aAAa,IAAI,UAA+B,kBAAkB,MAAM;AAC9E,WAAO,IAAI,aAAa;AAAA,MACtB,QAAQ;AAAA,QACN,QAAQ,IAAI,IAAI,QAAQ;AAAA,QACxB,kBAAkB,IAAI,IAAI,kBAAkB;AAAA,QAC5C,UAAU,IAAI,IAAI,UAAU;AAAA,QAC5B,WAAW,IAAI,IAAI,WAAW;AAAA,MAChC;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,CAAC,EAAE,cAAc;AAAA,EACnB;AACJ;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "../../chunk-2B2CG5KL.js";
|
|
4
|
+
import { middlewareCreator } from "../../utils";
|
|
5
|
+
class ForceHTTPS {
|
|
6
|
+
/**
|
|
7
|
+
* @param options The options to construct the class.
|
|
8
|
+
*/
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
/**
|
|
11
|
+
* The customization options.
|
|
12
|
+
*/
|
|
13
|
+
__publicField(this, "_options");
|
|
14
|
+
this._options = {
|
|
15
|
+
ignoredRoutes: [/^\/service\//],
|
|
16
|
+
...options
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generates the middleware that redirects the traffic.
|
|
21
|
+
*/
|
|
22
|
+
getMiddleware() {
|
|
23
|
+
return (req, res, next) => {
|
|
24
|
+
if (!req.secure && req.get("X-Forwarded-Proto") !== "https" && !this._options.ignoredRoutes.some(
|
|
25
|
+
(expression) => expression.test(req.originalUrl)
|
|
26
|
+
)) {
|
|
27
|
+
const host = req.get("Host");
|
|
28
|
+
res.redirect(`https://${host}${req.url}`);
|
|
29
|
+
} else {
|
|
30
|
+
next();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The customization options.
|
|
36
|
+
*/
|
|
37
|
+
get options() {
|
|
38
|
+
return { ...this._options };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const forceHTTPSMiddleware = middlewareCreator(
|
|
42
|
+
(options = {}) => (app) => {
|
|
43
|
+
const enabled = app.getConfig("forceHTTPS");
|
|
44
|
+
if (!enabled)
|
|
45
|
+
return void 0;
|
|
46
|
+
return new ForceHTTPS(options).getMiddleware();
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
export {
|
|
50
|
+
ForceHTTPS,
|
|
51
|
+
forceHTTPSMiddleware
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=forceHTTPS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/middlewares/common/forceHTTPS.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils';\nimport { ExpressMiddleware } from '../../types';\n/**\n * The customization options for the middleware.\n *\n * @group Middlewares/ForceHTTPS\n */\nexport type ForceHTTPSOptions = {\n /**\n * A list of regular expressions to match routes that should be ignored.\n *\n * @default [/^\\/service\\//]\n */\n ignoredRoutes: RegExp[];\n};\n/**\n * A partial version of the {@link ForceHTTPSOptions}, to be used in the constructor and\n * the middleware creator.\n *\n * @group Middlewares/ForceHTTPS\n */\nexport type ForceHTTPSPartialOptions = Partial<ForceHTTPSOptions>;\n/**\n * Creates a middleware that forces all the traffic to be through HTTPS.\n *\n * @group Middleware Classes\n * @group Middlewares/ForceHTTPS\n * @prettierignore\n */\nexport class ForceHTTPS {\n /**\n * The customization options.\n */\n protected readonly _options: ForceHTTPSOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor(options: ForceHTTPSPartialOptions = {}) {\n this._options = {\n ignoredRoutes: [/^\\/service\\//],\n ...options,\n };\n }\n /**\n * Generates the middleware that redirects the traffic.\n */\n getMiddleware(): ExpressMiddleware {\n return (req, res, next) => {\n if (\n !req.secure &&\n req.get('X-Forwarded-Proto') !== 'https' &&\n !this._options.ignoredRoutes.some((expression) =>\n expression.test(req.originalUrl),\n )\n ) {\n const host = req.get('Host');\n res.redirect(`https://${host}${req.url}`);\n } else {\n next();\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<ForceHTTPSOptions> {\n return { ...this._options };\n }\n}\n/**\n * Creates the middleware that redirects the traffic to HTTPS.\n *\n * @group Middlewares\n * @group Middlewares/ForceHTTPS\n */\nexport const forceHTTPSMiddleware = middlewareCreator(\n (options: ForceHTTPSPartialOptions = {}) =>\n (app) => {\n const enabled = app.getConfig<boolean | undefined>('forceHTTPS');\n if (!enabled) return undefined;\n return new ForceHTTPS(options).getMiddleware();\n },\n);\n"],"mappings":";;;AAAA,SAAS,yBAAyB;AA6B3B,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA,EAQtB,YAAY,UAAoC,CAAC,GAAG;AAJpD;AAAA;AAAA;AAAA,wBAAmB;AAKjB,SAAK,WAAW;AAAA,MACd,eAAe,CAAC,cAAc;AAAA,MAC9B,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAmC;AACjC,WAAO,CAAC,KAAK,KAAK,SAAS;AACzB,UACE,CAAC,IAAI,UACL,IAAI,IAAI,mBAAmB,MAAM,WACjC,CAAC,KAAK,SAAS,cAAc;AAAA,QAAK,CAAC,eACjC,WAAW,KAAK,IAAI,WAAW;AAAA,MACjC,GACA;AACA,cAAM,OAAO,IAAI,IAAI,MAAM;AAC3B,YAAI,SAAS,WAAW,IAAI,GAAG,IAAI,GAAG,EAAE;AAAA,MAC1C,OAAO;AACL,aAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAuC;AACzC,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AACF;AAOO,MAAM,uBAAuB;AAAA,EAClC,CAAC,UAAoC,CAAC,MACpC,CAAC,QAAQ;AACP,UAAM,UAAU,IAAI,UAA+B,YAAY;AAC/D,QAAI,CAAC;AAAS,aAAO;AACrB,WAAO,IAAI,WAAW,OAAO,EAAE,cAAc;AAAA,EAC/C;AACJ;","names":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "../../chunk-2B2CG5KL.js";
|
|
4
|
+
import { middlewareCreator } from "../../utils";
|
|
5
|
+
class HSTS {
|
|
6
|
+
/**
|
|
7
|
+
* @param options The options to construct the class.
|
|
8
|
+
*/
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
/**
|
|
11
|
+
* The customization options for the header.
|
|
12
|
+
*/
|
|
13
|
+
__publicField(this, "_options");
|
|
14
|
+
/**
|
|
15
|
+
* The value of the header that will be included in the responses.
|
|
16
|
+
*/
|
|
17
|
+
__publicField(this, "_header");
|
|
18
|
+
this._options = {
|
|
19
|
+
maxAge: 31536e3,
|
|
20
|
+
includeSubDomains: true,
|
|
21
|
+
preload: false,
|
|
22
|
+
...options
|
|
23
|
+
};
|
|
24
|
+
this._header = this._buildHeader();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates the middleware that includes the HSTS header on the responses.
|
|
28
|
+
*/
|
|
29
|
+
getMiddleware() {
|
|
30
|
+
return (_, res, next) => {
|
|
31
|
+
res.setHeader("Strict-Transport-Security", this._header);
|
|
32
|
+
next();
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The customization options.
|
|
37
|
+
*/
|
|
38
|
+
get options() {
|
|
39
|
+
return { ...this._options };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The value of the header that will be included in the responses.
|
|
43
|
+
*/
|
|
44
|
+
get header() {
|
|
45
|
+
return this._header;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates the header value based on the customization options.
|
|
49
|
+
*/
|
|
50
|
+
_buildHeader() {
|
|
51
|
+
const { maxAge, includeSubDomains, preload } = this._options;
|
|
52
|
+
const directives = [`max-age=${maxAge}`];
|
|
53
|
+
if (includeSubDomains) {
|
|
54
|
+
directives.push("includeSubDomains");
|
|
55
|
+
}
|
|
56
|
+
if (preload) {
|
|
57
|
+
directives.push("preload");
|
|
58
|
+
}
|
|
59
|
+
return directives.join("; ");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const hstsMiddleware = middlewareCreator(
|
|
63
|
+
(options = {}) => (app) => {
|
|
64
|
+
const setting = app.getConfig("hsts");
|
|
65
|
+
if (!setting?.enabled || typeof options.enabled !== "undefined" && !options.enabled)
|
|
66
|
+
return void 0;
|
|
67
|
+
return new HSTS(options).getMiddleware();
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
export {
|
|
71
|
+
HSTS,
|
|
72
|
+
hstsMiddleware
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=hsts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/middlewares/common/hsts.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils';\nimport { ExpressMiddleware } from '../../types';\n/**\n * The options to customize the HSTS header value.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security}\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewareOptions = {\n /**\n * The time, in seconds, that the browser should remember that a site is only to be\n * accessed using HTTPS.\n *\n * @default 31536000\n */\n maxAge: number;\n /**\n * Whether or not the rule should apply to all sub domains.\n *\n * @default true\n */\n includeSubDomains: boolean;\n /**\n * Whether or not to include on the major browsers'\n * preload list. This directive is not part of the specification, for more information\n * about it, you should check the MDN documentation for the header.\n *\n * @default false\n */\n preload: boolean;\n};\n/**\n * A partial version of the {@link HSTSMiddlewareOptions}, to be used in the constructor\n * and the middleware creator.\n *\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewarePartialOptions = Partial<HSTSMiddlewareOptions>;\n/**\n * The options for the middleware creator that will create the middleware, or not,\n * depending on the `enabled` option.\n *\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewareSettings = HSTSMiddlewarePartialOptions & {\n /**\n * If it's not `true`, it won't return the middleware.\n */\n enabled?: boolean;\n};\n/**\n * Generates a middleware that includes the HSTS header on the responses.\n *\n * @see {@link https://tools.ietf.org/html/rfc6797}\n * @group Middleware Classes\n * @group Middlewares/HSTS\n * @prettierignore\n */\nexport class HSTS {\n /**\n * The customization options for the header.\n */\n protected readonly _options: HSTSMiddlewareOptions;\n /**\n * The value of the header that will be included in the responses.\n */\n protected readonly _header: string;\n /**\n * @param options The options to construct the class.\n */\n constructor(options: HSTSMiddlewarePartialOptions = {}) {\n this._options = {\n maxAge: 31536000,\n includeSubDomains: true,\n preload: false,\n ...options,\n };\n this._header = this._buildHeader();\n }\n /**\n * Generates the middleware that includes the HSTS header on the responses.\n */\n getMiddleware(): ExpressMiddleware {\n return (_, res, next) => {\n res.setHeader('Strict-Transport-Security', this._header);\n next();\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<HSTSMiddlewareOptions> {\n return { ...this._options };\n }\n /**\n * The value of the header that will be included in the responses.\n */\n get header(): string {\n return this._header;\n }\n /**\n * Creates the header value based on the customization options.\n */\n protected _buildHeader(): string {\n const { maxAge, includeSubDomains, preload } = this._options;\n const directives = [`max-age=${maxAge}`];\n if (includeSubDomains) {\n directives.push('includeSubDomains');\n }\n\n if (preload) {\n directives.push('preload');\n }\n\n return directives.join('; ');\n }\n}\n/**\n * Creates the middleware that includes the HSTS header on the responses.\n *\n * @group Middlewares\n * @group Middlewares/HSTS\n */\nexport const hstsMiddleware = middlewareCreator(\n (options: HSTSMiddlewareSettings = {}) =>\n (app) => {\n const setting = app.getConfig<HSTSMiddlewareSettings | undefined>('hsts');\n if (\n !setting?.enabled ||\n (typeof options.enabled !== 'undefined' && !options.enabled)\n )\n return undefined;\n return new HSTS(options).getMiddleware();\n },\n);\n"],"mappings":";;;AAAA,SAAS,yBAAyB;AA0D3B,MAAM,KAAK;AAAA;AAAA;AAAA;AAAA,EAYhB,YAAY,UAAwC,CAAC,GAAG;AARxD;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAKjB,SAAK,WAAW;AAAA,MACd,QAAQ;AAAA,MACR,mBAAmB;AAAA,MACnB,SAAS;AAAA,MACT,GAAG;AAAA,IACL;AACA,SAAK,UAAU,KAAK,aAAa;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAmC;AACjC,WAAO,CAAC,GAAG,KAAK,SAAS;AACvB,UAAI,UAAU,6BAA6B,KAAK,OAAO;AACvD,WAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAA2C;AAC7C,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,SAAiB;AACnB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAIU,eAAuB;AAC/B,UAAM,EAAE,QAAQ,mBAAmB,QAAQ,IAAI,KAAK;AACpD,UAAM,aAAa,CAAC,WAAW,MAAM,EAAE;AACvC,QAAI,mBAAmB;AACrB,iBAAW,KAAK,mBAAmB;AAAA,IACrC;AAEA,QAAI,SAAS;AACX,iBAAW,KAAK,SAAS;AAAA,IAC3B;AAEA,WAAO,WAAW,KAAK,IAAI;AAAA,EAC7B;AACF;AAOO,MAAM,iBAAiB;AAAA,EAC5B,CAAC,UAAkC,CAAC,MAClC,CAAC,QAAQ;AACP,UAAM,UAAU,IAAI,UAA8C,MAAM;AACxE,QACE,CAAC,SAAS,WACT,OAAO,QAAQ,YAAY,eAAe,CAAC,QAAQ;AAEpD,aAAO;AACT,WAAO,IAAI,KAAK,OAAO,EAAE,cAAc;AAAA,EACzC;AACJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/middlewares/common/index.ts"],"sourcesContent":["export * from './errorHandler';\nexport * from './forceHTTPS';\nexport * from './hsts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "../../chunk-2B2CG5KL.js";
|
|
4
|
+
import { createRouteExpression, middlewareCreator, removeSlashes } from "../../utils";
|
|
5
|
+
class FastHTML {
|
|
6
|
+
/**
|
|
7
|
+
* @param options The options to construct the class.
|
|
8
|
+
* @throws If `ignoredRoutes` is empty and `useAppRoutes` is set to `false`.
|
|
9
|
+
*/
|
|
10
|
+
constructor({ inject, ...options }) {
|
|
11
|
+
/**
|
|
12
|
+
* The service that serves a file.
|
|
13
|
+
*/
|
|
14
|
+
__publicField(this, "_sendFile");
|
|
15
|
+
/**
|
|
16
|
+
* The application envent bus, to listen and get the list of "controlled routes" after
|
|
17
|
+
* the application is started.
|
|
18
|
+
*/
|
|
19
|
+
__publicField(this, "_events");
|
|
20
|
+
/**
|
|
21
|
+
* A function to get a possible {@link HTMLGenerator}. This is injected as a "getter"
|
|
22
|
+
* to not interrupt the DIC "lifecycle": middlewares are initialized right when the
|
|
23
|
+
* app starts, and injecting a reference would force the service to be initialized
|
|
24
|
+
* too, even if a request is not being made.
|
|
25
|
+
*/
|
|
26
|
+
__publicField(this, "_getHTMLGenerator");
|
|
27
|
+
/**
|
|
28
|
+
* The customization options for the middleware.
|
|
29
|
+
*/
|
|
30
|
+
__publicField(this, "_options");
|
|
31
|
+
/**
|
|
32
|
+
* Whether or not the file is ready to be served. In case the middleware uses an
|
|
33
|
+
* {@link HTMLGenerator} service, the file needs to be generated before being available,
|
|
34
|
+
* and that's why this flag exists.
|
|
35
|
+
*/
|
|
36
|
+
__publicField(this, "_fileReady", false);
|
|
37
|
+
/**
|
|
38
|
+
* A list of regular expression that match the routes controlled by the application.
|
|
39
|
+
* This is in case the `useAppRoutes` option is set to `true`; when the application gets
|
|
40
|
+
* started, an event listener will obtain all the top controlled routes, create regular
|
|
41
|
+
* expressions, and save them on this property.
|
|
42
|
+
*/
|
|
43
|
+
__publicField(this, "_routeExpressions", []);
|
|
44
|
+
this._sendFile = inject.sendFile;
|
|
45
|
+
this._events = inject.events;
|
|
46
|
+
this._getHTMLGenerator = inject.getHTMLGenerator || (() => void 0);
|
|
47
|
+
this._options = {
|
|
48
|
+
file: "index.html",
|
|
49
|
+
ignoredRoutes: [/\.ico$/i],
|
|
50
|
+
useAppRoutes: true,
|
|
51
|
+
...options
|
|
52
|
+
};
|
|
53
|
+
if (!this._options.ignoredRoutes.length && !this._options.useAppRoutes) {
|
|
54
|
+
throw new Error("You must provide either `ignoredRoutes` or `useAppRoutes`");
|
|
55
|
+
}
|
|
56
|
+
if (this._options.useAppRoutes) {
|
|
57
|
+
this._setupEvents();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generates the middleware that serves the HTML file.
|
|
62
|
+
*/
|
|
63
|
+
getMiddleware() {
|
|
64
|
+
return async (req, res, next) => {
|
|
65
|
+
if (this._shouldIgnoreRoute(req.originalUrl)) {
|
|
66
|
+
next();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (this._fileReady) {
|
|
70
|
+
this._sendResponse(res, next);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const htmlGenerator = this._getHTMLGenerator();
|
|
74
|
+
if (!htmlGenerator) {
|
|
75
|
+
this._fileReady = true;
|
|
76
|
+
this._sendResponse(res, next);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await htmlGenerator.whenReady();
|
|
81
|
+
this._options.file = htmlGenerator.options.file;
|
|
82
|
+
this._fileReady = true;
|
|
83
|
+
this._sendResponse(res, next);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
next(error);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The customization options.
|
|
91
|
+
*/
|
|
92
|
+
get options() {
|
|
93
|
+
return { ...this._options };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Serves the HTML file to the response.
|
|
97
|
+
*
|
|
98
|
+
* @param res The response object generated by the application.
|
|
99
|
+
* @param next The function to call the next middleware.
|
|
100
|
+
*/
|
|
101
|
+
_sendResponse(res, next) {
|
|
102
|
+
res.setHeader("Content-Type", "text/html");
|
|
103
|
+
this._sendFile({
|
|
104
|
+
res,
|
|
105
|
+
next,
|
|
106
|
+
filepath: this._options.file
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Adds the event listener that obtains the list of "controlled routes" when
|
|
111
|
+
* `useAppRoutes` is set to `true`.
|
|
112
|
+
*/
|
|
113
|
+
_setupEvents() {
|
|
114
|
+
this._events.once("afterStart", ({ app }) => {
|
|
115
|
+
const [routeExpressions] = app.routes.reduce(
|
|
116
|
+
(acc, route) => {
|
|
117
|
+
const [expressions, processed] = acc;
|
|
118
|
+
const clean = removeSlashes(route).trim();
|
|
119
|
+
if (!clean || processed.includes(clean))
|
|
120
|
+
return acc;
|
|
121
|
+
expressions.push(createRouteExpression(clean));
|
|
122
|
+
processed.push(clean);
|
|
123
|
+
return acc;
|
|
124
|
+
},
|
|
125
|
+
[[], []]
|
|
126
|
+
);
|
|
127
|
+
this._routeExpressions.push(...routeExpressions);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validates whether a route should be ignored or not. The method checks first against
|
|
132
|
+
* the `ignore` option, and then against the list of "controlled routes" if
|
|
133
|
+
* `useAppRoutes` is set to `true`.
|
|
134
|
+
*
|
|
135
|
+
* @param route The route to validate.
|
|
136
|
+
*/
|
|
137
|
+
_shouldIgnoreRoute(route) {
|
|
138
|
+
return this._options.ignoredRoutes.some((expression) => route.match(expression)) || this._routeExpressions.some((expression) => route.match(expression));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const fastHTMLMiddleware = middlewareCreator(
|
|
142
|
+
(options = {}) => (app) => {
|
|
143
|
+
const { htmlGeneratorServiceName = "htmlGenerator", ...rest } = options;
|
|
144
|
+
return new FastHTML({
|
|
145
|
+
inject: {
|
|
146
|
+
events: app.get("events"),
|
|
147
|
+
sendFile: app.get("sendFile"),
|
|
148
|
+
getHTMLGenerator: () => app.try(htmlGeneratorServiceName)
|
|
149
|
+
},
|
|
150
|
+
...rest
|
|
151
|
+
}).getMiddleware();
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
export {
|
|
155
|
+
FastHTML,
|
|
156
|
+
fastHTMLMiddleware
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=fastHTML.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/middlewares/html/fastHTML.ts"],"sourcesContent":["import { createRouteExpression, middlewareCreator, removeSlashes } from '../../utils';\nimport type { HTMLGenerator, SendFile } from '../../services';\nimport type { AsyncExpressMiddleware, Response, NextFunction, Events } from '../../types';\n/**\n * The options to customize the behavior of the middleware.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLOptions = {\n /**\n * The name of the file the middleware will serve. If the {@link HTMLGenerator} service\n * is available, it will be overriden by the service.\n *\n * @default 'index.html'\n */\n file: string;\n /**\n * A list of regular expressions to match request paths that should be ignored by the\n * middleware.\n *\n * @default [/\\.ico$/i]\n */\n ignoredRoutes: RegExp[];\n /**\n * If `true`, {@link FastHTML} will get the list of all the routes controlled by the\n * application, and will use them to validate the incoming requests (in addition to the\n * `ignore` list): If a request URL doesn't match with any of the \"controlled routes\",\n * it will serve the HTML file.\n *\n * @default true\n */\n useAppRoutes: boolean;\n};\n/**\n * The options to construct a {@link FastHTML}.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLConstructorOptions = Partial<FastHTMLOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n sendFile: SendFile;\n events: Events;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n getHTMLGenerator?: () => HTMLGenerator | undefined;\n };\n};\n/**\n * The options for the middleware creator that will mount an instance of {@link FastHTML}.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLMiddlewareOptions = Partial<FastHTMLOptions> & {\n /**\n * The name of an {@link HTMLGenerator} service already available in the application.\n *\n * @default 'htmlGenerator'\n */\n htmlGeneratorServiceName?: string;\n};\n/**\n * It's common for an app to show an HTML view when no route was able to handle a request,\n * so the idea behind this middleware is to avoid going to every middleware and controller\n * and just specify that if the request is not for a route handled by a controller, just\n * serve the HTML and avoid processing unnecessary data.\n *\n * A simple example: The app has a route `/backend` that a frontend uses to get\n * information.\n * This middleware can be used to only allow the execution of middlewares and controllers\n * when the request route is for `/backend`.\n *\n * **Disclaimer**: Managing statics files with Express is not a best practice, but there\n * are scenarios where there is not other choice.\n *\n * @group Middleware Classes\n * @group Middlewares/FastHTML\n * @prettierignore\n */\nexport class FastHTML {\n /**\n * The service that serves a file.\n */\n protected readonly _sendFile: SendFile;\n /**\n * The application envent bus, to listen and get the list of \"controlled routes\" after\n * the application is started.\n */\n protected readonly _events: Events;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n protected readonly _getHTMLGenerator: () => HTMLGenerator | undefined;\n /**\n * The customization options for the middleware.\n */\n protected _options: FastHTMLOptions;\n /**\n * Whether or not the file is ready to be served. In case the middleware uses an\n * {@link HTMLGenerator} service, the file needs to be generated before being available,\n * and that's why this flag exists.\n */\n protected _fileReady: boolean = false;\n /**\n * A list of regular expression that match the routes controlled by the application.\n * This is in case the `useAppRoutes` option is set to `true`; when the application gets\n * started, an event listener will obtain all the top controlled routes, create regular\n * expressions, and save them on this property.\n */\n protected _routeExpressions: RegExp[] = [];\n /**\n * @param options The options to construct the class.\n * @throws If `ignoredRoutes` is empty and `useAppRoutes` is set to `false`.\n */\n constructor({ inject, ...options }: FastHTMLConstructorOptions) {\n this._sendFile = inject.sendFile;\n this._events = inject.events;\n this._getHTMLGenerator = inject.getHTMLGenerator || (() => undefined);\n this._options = {\n file: 'index.html',\n ignoredRoutes: [/\\.ico$/i],\n useAppRoutes: true,\n ...options,\n };\n\n if (!this._options.ignoredRoutes.length && !this._options.useAppRoutes) {\n throw new Error('You must provide either `ignoredRoutes` or `useAppRoutes`');\n }\n\n if (this._options.useAppRoutes) {\n this._setupEvents();\n }\n }\n /**\n * Generates the middleware that serves the HTML file.\n */\n getMiddleware(): AsyncExpressMiddleware {\n return async (req, res, next) => {\n // If the route should be ignored, move to the next middleware.\n if (this._shouldIgnoreRoute(req.originalUrl)) {\n next();\n return;\n }\n\n // If the file is ready to be served, serve it.\n if (this._fileReady) {\n this._sendResponse(res, next);\n return;\n }\n\n const htmlGenerator = this._getHTMLGenerator();\n // If there's no generator, switch the flag and just serve the file.\n if (!htmlGenerator) {\n this._fileReady = true;\n this._sendResponse(res, next);\n return;\n }\n\n try {\n // Wait for the HTML to be generated.\n await htmlGenerator.whenReady();\n // Update the local option.\n this._options.file = htmlGenerator.options.file;\n // Switch the flag and serve the file.\n this._fileReady = true;\n this._sendResponse(res, next);\n } catch (error) {\n next(error);\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<FastHTMLOptions> {\n return { ...this._options };\n }\n /**\n * Serves the HTML file to the response.\n *\n * @param res The response object generated by the application.\n * @param next The function to call the next middleware.\n */\n protected _sendResponse(res: Response, next: NextFunction): void {\n res.setHeader('Content-Type', 'text/html');\n this._sendFile({\n res,\n next,\n filepath: this._options.file,\n });\n }\n /**\n * Adds the event listener that obtains the list of \"controlled routes\" when\n * `useAppRoutes` is set to `true`.\n */\n protected _setupEvents() {\n this._events.once('afterStart', ({ app }) => {\n const [routeExpressions] = app.routes.reduce<[RegExp[], string[]]>(\n (acc, route) => {\n const [expressions, processed] = acc;\n const clean = removeSlashes(route).trim();\n if (!clean || processed.includes(clean)) return acc;\n expressions.push(createRouteExpression(clean));\n processed.push(clean);\n return acc;\n },\n [[], []],\n );\n this._routeExpressions.push(...routeExpressions);\n });\n }\n /**\n * Validates whether a route should be ignored or not. The method checks first against\n * the `ignore` option, and then against the list of \"controlled routes\" if\n * `useAppRoutes` is set to `true`.\n *\n * @param route The route to validate.\n */\n protected _shouldIgnoreRoute(route: string): boolean {\n return (\n this._options.ignoredRoutes.some((expression) => route.match(expression)) ||\n this._routeExpressions.some((expression) => route.match(expression))\n );\n }\n}\n/**\n * Creates the middleware that filters the routes and serves an HTML before the\n * application gets to evaluate whether there's a controller for the request or not.\n *\n * @group Middlewares\n * @group Middlewares/FastHTML\n */\nexport const fastHTMLMiddleware = middlewareCreator(\n (options: FastHTMLMiddlewareOptions = {}) =>\n (app) => {\n const { htmlGeneratorServiceName = 'htmlGenerator', ...rest } = options;\n return new FastHTML({\n inject: {\n events: app.get('events'),\n sendFile: app.get('sendFile'),\n getHTMLGenerator: () => app.try(htmlGeneratorServiceName),\n },\n ...rest,\n }).getMiddleware();\n },\n);\n"],"mappings":";;;AAAA,SAAS,uBAAuB,mBAAmB,qBAAqB;AAqFjE,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAsCpB,YAAY,EAAE,QAAQ,GAAG,QAAQ,GAA+B;AAlChE;AAAA;AAAA;AAAA,wBAAmB;AAKnB;AAAA;AAAA;AAAA;AAAA,wBAAmB;AAOnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAU;AAMV;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAU,cAAsB;AAOhC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAU,qBAA8B,CAAC;AAMvC,SAAK,YAAY,OAAO;AACxB,SAAK,UAAU,OAAO;AACtB,SAAK,oBAAoB,OAAO,qBAAqB,MAAM;AAC3D,SAAK,WAAW;AAAA,MACd,MAAM;AAAA,MACN,eAAe,CAAC,SAAS;AAAA,MACzB,cAAc;AAAA,MACd,GAAG;AAAA,IACL;AAEA,QAAI,CAAC,KAAK,SAAS,cAAc,UAAU,CAAC,KAAK,SAAS,cAAc;AACtE,YAAM,IAAI,MAAM,2DAA2D;AAAA,IAC7E;AAEA,QAAI,KAAK,SAAS,cAAc;AAC9B,WAAK,aAAa;AAAA,IACpB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAwC;AACtC,WAAO,OAAO,KAAK,KAAK,SAAS;AAE/B,UAAI,KAAK,mBAAmB,IAAI,WAAW,GAAG;AAC5C,aAAK;AACL;AAAA,MACF;AAGA,UAAI,KAAK,YAAY;AACnB,aAAK,cAAc,KAAK,IAAI;AAC5B;AAAA,MACF;AAEA,YAAM,gBAAgB,KAAK,kBAAkB;AAE7C,UAAI,CAAC,eAAe;AAClB,aAAK,aAAa;AAClB,aAAK,cAAc,KAAK,IAAI;AAC5B;AAAA,MACF;AAEA,UAAI;AAEF,cAAM,cAAc,UAAU;AAE9B,aAAK,SAAS,OAAO,cAAc,QAAQ;AAE3C,aAAK,aAAa;AAClB,aAAK,cAAc,KAAK,IAAI;AAAA,MAC9B,SAAS,OAAO;AACd,aAAK,KAAK;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAqC;AACvC,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,KAAe,MAA0B;AAC/D,QAAI,UAAU,gBAAgB,WAAW;AACzC,SAAK,UAAU;AAAA,MACb;AAAA,MACA;AAAA,MACA,UAAU,KAAK,SAAS;AAAA,IAC1B,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAKU,eAAe;AACvB,SAAK,QAAQ,KAAK,cAAc,CAAC,EAAE,IAAI,MAAM;AAC3C,YAAM,CAAC,gBAAgB,IAAI,IAAI,OAAO;AAAA,QACpC,CAAC,KAAK,UAAU;AACd,gBAAM,CAAC,aAAa,SAAS,IAAI;AACjC,gBAAM,QAAQ,cAAc,KAAK,EAAE,KAAK;AACxC,cAAI,CAAC,SAAS,UAAU,SAAS,KAAK;AAAG,mBAAO;AAChD,sBAAY,KAAK,sBAAsB,KAAK,CAAC;AAC7C,oBAAU,KAAK,KAAK;AACpB,iBAAO;AAAA,QACT;AAAA,QACA,CAAC,CAAC,GAAG,CAAC,CAAC;AAAA,MACT;AACA,WAAK,kBAAkB,KAAK,GAAG,gBAAgB;AAAA,IACjD,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,mBAAmB,OAAwB;AACnD,WACE,KAAK,SAAS,cAAc,KAAK,CAAC,eAAe,MAAM,MAAM,UAAU,CAAC,KACxE,KAAK,kBAAkB,KAAK,CAAC,eAAe,MAAM,MAAM,UAAU,CAAC;AAAA,EAEvE;AACF;AAQO,MAAM,qBAAqB;AAAA,EAChC,CAAC,UAAqC,CAAC,MACrC,CAAC,QAAQ;AACP,UAAM,EAAE,2BAA2B,iBAAiB,GAAG,KAAK,IAAI;AAChE,WAAO,IAAI,SAAS;AAAA,MAClB,QAAQ;AAAA,QACN,QAAQ,IAAI,IAAI,QAAQ;AAAA,QACxB,UAAU,IAAI,IAAI,UAAU;AAAA,QAC5B,kBAAkB,MAAM,IAAI,IAAI,wBAAwB;AAAA,MAC1D;AAAA,MACA,GAAG;AAAA,IACL,CAAC,EAAE,cAAc;AAAA,EACnB;AACJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/middlewares/html/index.ts"],"sourcesContent":["export * from './fastHTML';\nexport * from './showHTML';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "../../chunk-2B2CG5KL.js";
|
|
4
|
+
import { middlewareCreator } from "../../utils";
|
|
5
|
+
class ShowHTML {
|
|
6
|
+
/**
|
|
7
|
+
* @param options The options to construct the class.
|
|
8
|
+
*/
|
|
9
|
+
constructor({ inject, ...options }) {
|
|
10
|
+
/**
|
|
11
|
+
* The service that serves a file.
|
|
12
|
+
*/
|
|
13
|
+
__publicField(this, "_sendFile");
|
|
14
|
+
/**
|
|
15
|
+
* A function to get a possible {@link HTMLGenerator}. This is injected as a "getter"
|
|
16
|
+
* to not interrupt the DIC "lifecycle": middlewares are initialized right when the
|
|
17
|
+
* app starts, and injecting a reference would force the service to be initialized
|
|
18
|
+
* too, even if a request is not being made.
|
|
19
|
+
*/
|
|
20
|
+
__publicField(this, "_getHTMLGenerator");
|
|
21
|
+
/**
|
|
22
|
+
* The customization options for the middleware.
|
|
23
|
+
*/
|
|
24
|
+
__publicField(this, "_options");
|
|
25
|
+
/**
|
|
26
|
+
* Whether or not the file is ready to be served. In case the middleware uses an
|
|
27
|
+
* {@link HTMLGenerator} service, the file needs to be generated before being available,
|
|
28
|
+
* and that's why this flag exists.
|
|
29
|
+
*/
|
|
30
|
+
__publicField(this, "_fileReady", false);
|
|
31
|
+
this._sendFile = inject.sendFile;
|
|
32
|
+
this._getHTMLGenerator = inject.getHTMLGenerator || (() => void 0);
|
|
33
|
+
this._options = {
|
|
34
|
+
file: "index.html",
|
|
35
|
+
...options
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generates the middleware that serves the HTML file.
|
|
40
|
+
*/
|
|
41
|
+
getMiddleware() {
|
|
42
|
+
return async (_, res, next) => {
|
|
43
|
+
if (this._fileReady) {
|
|
44
|
+
this._sendResponse(res, next);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const htmlGenerator = this._getHTMLGenerator();
|
|
48
|
+
if (!htmlGenerator) {
|
|
49
|
+
this._fileReady = true;
|
|
50
|
+
this._sendResponse(res, next);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await htmlGenerator.whenReady();
|
|
55
|
+
this._options.file = htmlGenerator.options.file;
|
|
56
|
+
this._fileReady = true;
|
|
57
|
+
this._sendResponse(res, next);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
next(error);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The customization options.
|
|
65
|
+
*/
|
|
66
|
+
get options() {
|
|
67
|
+
return { ...this._options };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Serves the HTML file to the response.
|
|
71
|
+
*
|
|
72
|
+
* @param res The response object generated by the application.
|
|
73
|
+
* @param next The function to call the next middleware.
|
|
74
|
+
*/
|
|
75
|
+
_sendResponse(res, next) {
|
|
76
|
+
res.setHeader("Content-Type", "text/html");
|
|
77
|
+
this._sendFile({
|
|
78
|
+
res,
|
|
79
|
+
next,
|
|
80
|
+
filepath: this._options.file
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const showHTMLMiddleware = middlewareCreator(
|
|
85
|
+
(options = {}) => (app) => {
|
|
86
|
+
const { htmlGeneratorServiceName = "htmlGenerator", ...rest } = options;
|
|
87
|
+
return new ShowHTML({
|
|
88
|
+
inject: {
|
|
89
|
+
sendFile: app.get("sendFile"),
|
|
90
|
+
getHTMLGenerator: () => app.try(htmlGeneratorServiceName)
|
|
91
|
+
},
|
|
92
|
+
...rest
|
|
93
|
+
}).getMiddleware();
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
export {
|
|
97
|
+
ShowHTML,
|
|
98
|
+
showHTMLMiddleware
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=showHTML.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/middlewares/html/showHTML.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils';\nimport type { HTMLGenerator, SendFile } from '../../services';\nimport type { AsyncExpressMiddleware, Response, NextFunction } from '../../types';\n/**\n * The options to customize the behavior of the middleware.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLOptions = {\n /**\n * The name of the file the middleware will serve. If the {@link HTMLGenerator} service\n * is available, it will be overriden by the service.\n *\n * @default 'index.html'\n */\n file: string;\n};\n/**\n * The options to construct a {@link ShowHTML}.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLConstructorOptions = Partial<ShowHTMLOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n sendFile: SendFile;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n getHTMLGenerator?: () => HTMLGenerator | undefined;\n };\n};\n/**\n * The options for the middleware creator that will mount an instance of {@link ShowHTML}.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLMiddlewareOptions = Partial<ShowHTMLOptions> & {\n /**\n * The name of an {@link HTMLGenerator} service already available in the application.\n *\n * @default 'htmlGenerator'\n */\n htmlGeneratorServiceName?: string;\n};\n\n/**\n * A very simple middleware service to send an HTML on a server response. The special\n * _'feature'_ of this service is that it can be hooked up to an {@link HTMLGenerator}\n * service and it will automatically server the file generated by it.\n *\n * @group Middleware Classes\n * @group Middlewares/ShowHTML\n * @prettierignore\n */\nexport class ShowHTML {\n /**\n * The service that serves a file.\n */\n protected readonly _sendFile: SendFile;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n protected readonly _getHTMLGenerator: () => HTMLGenerator | undefined;\n /**\n * The customization options for the middleware.\n */\n protected _options: ShowHTMLOptions;\n /**\n * Whether or not the file is ready to be served. In case the middleware uses an\n * {@link HTMLGenerator} service, the file needs to be generated before being available,\n * and that's why this flag exists.\n */\n protected _fileReady: boolean = false;\n /**\n * @param options The options to construct the class.\n */\n constructor({ inject, ...options }: ShowHTMLConstructorOptions) {\n this._sendFile = inject.sendFile;\n this._getHTMLGenerator = inject.getHTMLGenerator || (() => undefined);\n this._options = {\n file: 'index.html',\n ...options,\n };\n }\n /**\n * Generates the middleware that serves the HTML file.\n */\n getMiddleware(): AsyncExpressMiddleware {\n return async (_, res, next) => {\n // If the file is ready to be served, serve it.\n if (this._fileReady) {\n this._sendResponse(res, next);\n return;\n }\n\n const htmlGenerator = this._getHTMLGenerator();\n // If there's no generator, switch the flag and just serve the file.\n if (!htmlGenerator) {\n this._fileReady = true;\n this._sendResponse(res, next);\n return;\n }\n\n try {\n // Wait for the HTML to be generated.\n await htmlGenerator.whenReady();\n // Update the local option.\n this._options.file = htmlGenerator.options.file;\n // Switch the flag and serve the file.\n this._fileReady = true;\n this._sendResponse(res, next);\n } catch (error) {\n next(error);\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<ShowHTMLOptions> {\n return { ...this._options };\n }\n /**\n * Serves the HTML file to the response.\n *\n * @param res The response object generated by the application.\n * @param next The function to call the next middleware.\n */\n protected _sendResponse(res: Response, next: NextFunction): void {\n res.setHeader('Content-Type', 'text/html');\n this._sendFile({\n res,\n next,\n filepath: this._options.file,\n });\n }\n}\n/**\n * Creates the middleware that serves an HTML file in the response.\n *\n * @group Middlewares\n * @group Middlewares/ShowHTML\n */\nexport const showHTMLMiddleware = middlewareCreator(\n (options: ShowHTMLMiddlewareOptions = {}) =>\n (app) => {\n const { htmlGeneratorServiceName = 'htmlGenerator', ...rest } = options;\n return new ShowHTML({\n inject: {\n sendFile: app.get('sendFile'),\n getHTMLGenerator: () => app.try(htmlGeneratorServiceName),\n },\n ...rest,\n }).getMiddleware();\n },\n);\n"],"mappings":";;;AAAA,SAAS,yBAAyB;AA4D3B,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA,EAyBpB,YAAY,EAAE,QAAQ,GAAG,QAAQ,GAA+B;AArBhE;AAAA;AAAA;AAAA,wBAAmB;AAOnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAU;AAMV;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAU,cAAsB;AAK9B,SAAK,YAAY,OAAO;AACxB,SAAK,oBAAoB,OAAO,qBAAqB,MAAM;AAC3D,SAAK,WAAW;AAAA,MACd,MAAM;AAAA,MACN,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAwC;AACtC,WAAO,OAAO,GAAG,KAAK,SAAS;AAE7B,UAAI,KAAK,YAAY;AACnB,aAAK,cAAc,KAAK,IAAI;AAC5B;AAAA,MACF;AAEA,YAAM,gBAAgB,KAAK,kBAAkB;AAE7C,UAAI,CAAC,eAAe;AAClB,aAAK,aAAa;AAClB,aAAK,cAAc,KAAK,IAAI;AAC5B;AAAA,MACF;AAEA,UAAI;AAEF,cAAM,cAAc,UAAU;AAE9B,aAAK,SAAS,OAAO,cAAc,QAAQ;AAE3C,aAAK,aAAa;AAClB,aAAK,cAAc,KAAK,IAAI;AAAA,MAC9B,SAAS,OAAO;AACd,aAAK,KAAK;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAqC;AACvC,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,KAAe,MAA0B;AAC/D,QAAI,UAAU,gBAAgB,WAAW;AACzC,SAAK,UAAU;AAAA,MACb;AAAA,MACA;AAAA,MACA,UAAU,KAAK,SAAS;AAAA,IAC1B,CAAC;AAAA,EACH;AACF;AAOO,MAAM,qBAAqB;AAAA,EAChC,CAAC,UAAqC,CAAC,MACrC,CAAC,QAAQ;AACP,UAAM,EAAE,2BAA2B,iBAAiB,GAAG,KAAK,IAAI;AAChE,WAAO,IAAI,SAAS;AAAA,MAClB,QAAQ;AAAA,QACN,UAAU,IAAI,IAAI,UAAU;AAAA,QAC5B,kBAAkB,MAAM,IAAI,IAAI,wBAAwB;AAAA,MAC1D;AAAA,MACA,GAAG;AAAA,IACL,CAAC,EAAE,cAAc;AAAA,EACnB;AACJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/middlewares/index.ts"],"sourcesContent":["export * from './common';\nexport * from './html';\nexport * from './utils';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/middlewares/utils/index.ts"],"sourcesContent":["export * from './versionValidator';\n"],"mappings":"AAAA,cAAc;","names":[]}
|