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
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
const mime = require('mime');
|
|
2
|
-
const ObjectUtils = require('wootils/shared/objectUtils');
|
|
3
|
-
const { eventNames } = require('../../constants');
|
|
4
|
-
const { middlewareCreator } = require('../../utils/wrappers');
|
|
5
|
-
const { createRouteExpression, removeSlashes } = require('../../utils/functions');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {import('../../types').ExpressMiddleware} ExpressMiddleware
|
|
9
|
-
* @typedef {import('../../types').ExpressResponse} ExpressResponse
|
|
10
|
-
* @typedef {import('../../types').ExpressNext} ExpressNext
|
|
11
|
-
* @typedef {import('../../types').EventsHub} EventsHub
|
|
12
|
-
* @typedef {import('../../services/common/sendFile').SendFile} SendFile
|
|
13
|
-
* @typedef {import('../../services/html/htmlGenerator').HTMLGenerator} HTMLGenerator
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {import('../../types').MiddlewareCreator<O>} MiddlewareCreator<O>
|
|
18
|
-
* @template O
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The options to customize the behavior of the middleware.
|
|
23
|
-
*
|
|
24
|
-
* @typedef {Object} FastHTMLOptions
|
|
25
|
-
* @property {string} file The name of the file the middleware will serve. It
|
|
26
|
-
* can get overwritten if {@link FastHTML} receives an
|
|
27
|
-
* {@link HTMLGenerator}, in that case, the file will
|
|
28
|
-
* be obtained from that service. Default `index.html`.
|
|
29
|
-
* @property {RegExp[]} ignore A list of regular expressions to match requests
|
|
30
|
-
* paths that should be ignored.
|
|
31
|
-
* @property {boolean} useAppRoutes If `true`, {@link FastHTML} will get the list of all
|
|
32
|
-
* routes controlled by {@link Jimpex} and will use
|
|
33
|
-
* them to validate the incoming requests (in addition
|
|
34
|
-
* to `ignore`): If a request URL doesn't match with
|
|
35
|
-
* any of the controlled routes, it will show the HTML
|
|
36
|
-
* file. Default `true`.
|
|
37
|
-
* @parent module:middlewares
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @typedef {FastHTMLOptions & FastHTMLMiddlewareOptionsProperties} FastHTMLMiddlewareOptions
|
|
42
|
-
* @prettierignore
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @typedef {Object} FastHTMLMiddlewareOptionsProperties
|
|
47
|
-
* @property {string} htmlGenerator
|
|
48
|
-
* The name of a {@link HTMLGenerator} service for the middleware to use. Default
|
|
49
|
-
* `htmlGenerator`.
|
|
50
|
-
* @parent module:middlewares
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* It's common for an app to show an HTML view when no route was able to handle a request,
|
|
55
|
-
* so the idea behind this middleware is to avoid going to every middleware and controller
|
|
56
|
-
* and just specify that if the request is not for a route handled by a controller, just
|
|
57
|
-
* serve the HTML and avoid processing unnecessary data.
|
|
58
|
-
*
|
|
59
|
-
* A simple example: The app has a route `/backend` that a frontend uses to get
|
|
60
|
-
* information.
|
|
61
|
-
* This middleware can be used to only allow the execution of middlewares and controllers
|
|
62
|
-
* when the request route is for `/backend`.
|
|
63
|
-
*
|
|
64
|
-
* **Disclaimer**: Managing statics files with Express is not a best practice, but there
|
|
65
|
-
* are scenarios where there is not other choice.
|
|
66
|
-
*
|
|
67
|
-
* @parent module:middlewares
|
|
68
|
-
*/
|
|
69
|
-
class FastHTML {
|
|
70
|
-
/**
|
|
71
|
-
* @param {EventsHub} events To listen for the {@link Jimpex} event
|
|
72
|
-
* triggered after the app starts. The
|
|
73
|
-
* event is used to get all the
|
|
74
|
-
* controlled routes, in case the
|
|
75
|
-
* `useAppRoutes` option is set to true.
|
|
76
|
-
* @param {SendFile} sendFile To send the HTML file response.
|
|
77
|
-
* @param {FastHTMLOptions} [options={}] To customize the middleware behavior.
|
|
78
|
-
* @param {?HTMLGenerator} [htmlGenerator=null] If used, the file to serve will be the
|
|
79
|
-
* one generated by that service.
|
|
80
|
-
*/
|
|
81
|
-
constructor(events, sendFile, options = {}, htmlGenerator = null) {
|
|
82
|
-
/**
|
|
83
|
-
* A local reference for the `events` service.
|
|
84
|
-
*
|
|
85
|
-
* @type {EventsHub}
|
|
86
|
-
* @access protected
|
|
87
|
-
* @ignore
|
|
88
|
-
*/
|
|
89
|
-
this._events = events;
|
|
90
|
-
/**
|
|
91
|
-
* A local reference for the `sendFile` service.
|
|
92
|
-
*
|
|
93
|
-
* @type {SendFile}
|
|
94
|
-
* @access protected
|
|
95
|
-
* @ignore
|
|
96
|
-
*/
|
|
97
|
-
this._sendFile = sendFile;
|
|
98
|
-
/**
|
|
99
|
-
* If specified, a reference for a service that generates HTML files.
|
|
100
|
-
*
|
|
101
|
-
* @type {?HTMLGenerator}
|
|
102
|
-
* @access protected
|
|
103
|
-
* @ignore
|
|
104
|
-
*/
|
|
105
|
-
this._htmlGenerator = htmlGenerator;
|
|
106
|
-
/**
|
|
107
|
-
* The options that tell the middleware which routes should be ignored and which is
|
|
108
|
-
* the file to serve.
|
|
109
|
-
*
|
|
110
|
-
* @type {FastHTMLOptions}
|
|
111
|
-
*/
|
|
112
|
-
this._options = this._normalizeOptions(
|
|
113
|
-
ObjectUtils.merge(
|
|
114
|
-
{
|
|
115
|
-
file: 'index.html',
|
|
116
|
-
ignore: options.ignore || [/\.ico$/i],
|
|
117
|
-
useAppRoutes: true,
|
|
118
|
-
},
|
|
119
|
-
options,
|
|
120
|
-
),
|
|
121
|
-
);
|
|
122
|
-
/**
|
|
123
|
-
* Whether or not the file is ready to be served, in case there's an
|
|
124
|
-
* {@link HTMLGenerator}. If the service is used, the HTML is generated after the app
|
|
125
|
-
* starts,
|
|
126
|
-
* so the middleware will have to wait for it to be ready before being able to serve
|
|
127
|
-
* it.
|
|
128
|
-
*
|
|
129
|
-
* @type {boolean}
|
|
130
|
-
* @access protected
|
|
131
|
-
* @ignore
|
|
132
|
-
*/
|
|
133
|
-
this._ready = !this._htmlGenerator;
|
|
134
|
-
/**
|
|
135
|
-
* A list of regular expression that match the routes controlled by the app. This is
|
|
136
|
-
* in case the `useAppRoutes` option is set to `true`; when the app gets started, an
|
|
137
|
-
* event listener will obtain all the top controlled routes, create regular
|
|
138
|
-
* expressions and save them on this property.
|
|
139
|
-
*
|
|
140
|
-
* @type {RegExp[]}
|
|
141
|
-
* @access protected
|
|
142
|
-
* @ignore
|
|
143
|
-
*/
|
|
144
|
-
this._routeExpressions = [];
|
|
145
|
-
/**
|
|
146
|
-
* If the option to use the controlled routes is set to `true`, setup the event listener that
|
|
147
|
-
* gets all the routes when the app is started.
|
|
148
|
-
*/
|
|
149
|
-
if (this._options.useAppRoutes) {
|
|
150
|
-
this._setupEvents();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Returns the Express middleware that validates the routes and serves the HTML file if
|
|
155
|
-
* necessary.
|
|
156
|
-
*
|
|
157
|
-
* @returns {ExpressMiddleware}
|
|
158
|
-
*/
|
|
159
|
-
middleware() {
|
|
160
|
-
return (req, res, next) => {
|
|
161
|
-
if (this._shouldIgnore(req.originalUrl)) {
|
|
162
|
-
// If the route should be ignored, move to the next middleware.
|
|
163
|
-
next();
|
|
164
|
-
} else if (!this._ready) {
|
|
165
|
-
// If there's an HTMLGenerator and is not ready, wait for it...
|
|
166
|
-
this._htmlGenerator
|
|
167
|
-
.whenReady()
|
|
168
|
-
.then(() => {
|
|
169
|
-
// Change the flag to prevent the next execution to enter here.
|
|
170
|
-
this._ready = true;
|
|
171
|
-
// Serve the file.
|
|
172
|
-
this._sendHTML(res, next);
|
|
173
|
-
})
|
|
174
|
-
.catch((error) => {
|
|
175
|
-
// Something went wrong while generating the file, send the error to the error handler.
|
|
176
|
-
next(error);
|
|
177
|
-
});
|
|
178
|
-
} else {
|
|
179
|
-
// The route is not ignored and the file is ready to be served, so do it.
|
|
180
|
-
this._sendHTML(res, next);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* The options that tell the middleware which routes should be ignored and which is the
|
|
186
|
-
* file to serve.
|
|
187
|
-
*
|
|
188
|
-
* @type {FastHTMLOptions}
|
|
189
|
-
* @todo Remove Object.freeze.
|
|
190
|
-
*/
|
|
191
|
-
get options() {
|
|
192
|
-
return Object.freeze(this._options);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Normalizes and validates the options recevied on the constructor.
|
|
196
|
-
* If the class is using a {@link HTMLGenerator} service, the method will overwrite the
|
|
197
|
-
* `file`
|
|
198
|
-
* option with the result of the service's `getFile()` method.
|
|
199
|
-
*
|
|
200
|
-
* @param {FastHTMLOptions} options The received options.
|
|
201
|
-
* @returns {FastHTMLOptions}
|
|
202
|
-
* @throws {Error} If no file and no {@link HTMLGenerator} service are specified.
|
|
203
|
-
* @throws {Error} If no routes to ignore are specified and `useAppRoutes` is set to
|
|
204
|
-
* `false`.
|
|
205
|
-
* @access protected
|
|
206
|
-
* @ignore
|
|
207
|
-
*/
|
|
208
|
-
_normalizeOptions(options) {
|
|
209
|
-
if (!options.file && !this._htmlGenerator) {
|
|
210
|
-
throw new Error('You need to either define an HTMLGenerator service or a file');
|
|
211
|
-
} else if (!options.ignore.length && !options.useAppRoutes) {
|
|
212
|
-
throw new Error(
|
|
213
|
-
'You need to either define a list of routes to ignore or use `useAppRoutes`',
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return this._htmlGenerator
|
|
218
|
-
? { ...options, file: this._htmlGenerator.getFile() }
|
|
219
|
-
: options;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Serves the file on the response.
|
|
223
|
-
*
|
|
224
|
-
* @param {ExpressResponse} res The server response.
|
|
225
|
-
* @param {ExpressNext} next The function to call the next middleware.
|
|
226
|
-
* @access protected
|
|
227
|
-
* @ignore
|
|
228
|
-
*/
|
|
229
|
-
_sendHTML(res, next) {
|
|
230
|
-
res.setHeader('Content-Type', mime.getType('html'));
|
|
231
|
-
this._sendFile(res, this._options.file, next);
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Adds the event listener that obtains the controlled routes when `useAppRoutes` is set
|
|
235
|
-
* to `true`.
|
|
236
|
-
*
|
|
237
|
-
* @access protected
|
|
238
|
-
* @ignore
|
|
239
|
-
*/
|
|
240
|
-
_setupEvents() {
|
|
241
|
-
this._events.once(eventNames.afterStart, ({ routes }) => {
|
|
242
|
-
// Re generate the list of expressions...
|
|
243
|
-
this._routeExpressions = routes
|
|
244
|
-
// Remove leading and trailing slashes.
|
|
245
|
-
.map((route) => removeSlashes(route).trim())
|
|
246
|
-
// Filter empty routes (in case they were for `/`).
|
|
247
|
-
.filter((route) => route !== '')
|
|
248
|
-
// Remove repeated routes.
|
|
249
|
-
.reduce(
|
|
250
|
-
(unique, route) => (unique.includes(route) ? unique : [...unique, route]),
|
|
251
|
-
[],
|
|
252
|
-
)
|
|
253
|
-
// Generate regular expressions for each route.
|
|
254
|
-
.map((route) => createRouteExpression(route));
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Checks whether a route should be ignored or not. The method checks first against the
|
|
259
|
-
* `ignore`
|
|
260
|
-
* option, and then against the controlled routes (if `useAppRoutes` is `false`, the
|
|
261
|
-
* list will be empty).
|
|
262
|
-
*
|
|
263
|
-
* @param {string} route The route to validate.
|
|
264
|
-
* @returns {boolean}
|
|
265
|
-
* @access protected
|
|
266
|
-
* @ignore
|
|
267
|
-
*/
|
|
268
|
-
_shouldIgnore(route) {
|
|
269
|
-
return (
|
|
270
|
-
this._options.ignore.some((expression) => expression.test(route)) ||
|
|
271
|
-
this._routeExpressions.some((expression) => expression.test(route))
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* A middleware for filtering routes so you can serve an HTML before the app gets to
|
|
277
|
-
* evaluate whether there's a controller for the requested route or not. For more
|
|
278
|
-
* information about the reason of this middleware, please read the description of
|
|
279
|
-
* {@link FastHTML}.
|
|
280
|
-
*
|
|
281
|
-
* @type {MiddlewareCreator<FastHTMLMiddlewareOptions>}
|
|
282
|
-
* @parent module:middlewares
|
|
283
|
-
*/
|
|
284
|
-
const fastHTML = middlewareCreator((options = {}) => (app) => {
|
|
285
|
-
const htmlGeneratorServiceName =
|
|
286
|
-
typeof options.htmlGenerator === 'undefined'
|
|
287
|
-
? 'htmlGenerator'
|
|
288
|
-
: options.htmlGenerator;
|
|
289
|
-
return new FastHTML(
|
|
290
|
-
app.get('events'),
|
|
291
|
-
app.get('sendFile'),
|
|
292
|
-
options,
|
|
293
|
-
htmlGeneratorServiceName ? app.try(htmlGeneratorServiceName) : null,
|
|
294
|
-
).middleware();
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
module.exports.FastHTML = FastHTML;
|
|
298
|
-
module.exports.fastHTML = fastHTML;
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
const mime = require('mime');
|
|
2
|
-
const { middlewareCreator } = require('../../utils/wrappers');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {import('../../types').ExpressMiddleware} ExpressMiddleware
|
|
6
|
-
* @typedef {import('../../types').ExpressResponse} ExpressResponse
|
|
7
|
-
* @typedef {import('../../types').ExpressNext} ExpressNext
|
|
8
|
-
* @typedef {import('../../services/common/sendFile').SendFile} SendFile
|
|
9
|
-
* @typedef {import('../../services/html/htmlGenerator').HTMLGenerator} HTMLGenerator
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {import('../../types').MiddlewareCreator<O>} MiddlewareCreator<O>
|
|
14
|
-
* @template O
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A set options to customize the middleware behavior.
|
|
19
|
-
*
|
|
20
|
-
* @typedef {Object} ShowHTMLMiddlewareOptions
|
|
21
|
-
* @property {string} file The name of the file the middleware will serve.
|
|
22
|
-
* Default `'index.html'`.
|
|
23
|
-
* @property {string} htmlGenerator The name of a {@link HTMLGenerator} service for the
|
|
24
|
-
* middleware to use. If the service is available, the
|
|
25
|
-
* value of `file` will be overwritten for the file
|
|
26
|
-
* generated by the service. Default `'htmlGenerator'`.
|
|
27
|
-
* @parent module:middlewares
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* A very simple middleware service to send an HTML on a server response. The special
|
|
32
|
-
* _'feature'_ of this service is that it can be hooked up to an `HTMLGenerator` service
|
|
33
|
-
* and it will automatically server the file generated by it.
|
|
34
|
-
*
|
|
35
|
-
* @parent module:middlewares
|
|
36
|
-
*/
|
|
37
|
-
class ShowHTML {
|
|
38
|
-
/**
|
|
39
|
-
* @param {SendFile} sendFile Necessary to server the HTML file.
|
|
40
|
-
* @param {string} [file='index.html'] The name of the file it will serve. If
|
|
41
|
-
* `htmlGenerator` is specified, this will
|
|
42
|
-
* be overwritten with the name of the file
|
|
43
|
-
* generated by that service.
|
|
44
|
-
* @param {HTMLGenerator} [htmlGenerator=null] If used, the file to server will be the
|
|
45
|
-
* one generated by that service.
|
|
46
|
-
*/
|
|
47
|
-
constructor(sendFile, file = 'index.html', htmlGenerator = null) {
|
|
48
|
-
/**
|
|
49
|
-
* A local reference for the `sendFile` service.
|
|
50
|
-
*
|
|
51
|
-
* @type {SendFile}
|
|
52
|
-
* @access protected
|
|
53
|
-
* @ignore
|
|
54
|
-
*/
|
|
55
|
-
this._sendFile = sendFile;
|
|
56
|
-
/**
|
|
57
|
-
* The name of the file to serve.
|
|
58
|
-
*
|
|
59
|
-
* @type {string}
|
|
60
|
-
* @access protected
|
|
61
|
-
* @ignore
|
|
62
|
-
*/
|
|
63
|
-
this._file = file;
|
|
64
|
-
/**
|
|
65
|
-
* If specified, a reference for a service that generates HTML files.
|
|
66
|
-
*
|
|
67
|
-
* @type {HTMLGenerator}
|
|
68
|
-
* @access protected
|
|
69
|
-
* @ignore
|
|
70
|
-
*/
|
|
71
|
-
this._htmlGenerator = htmlGenerator;
|
|
72
|
-
/**
|
|
73
|
-
* Whether or not the file is ready to be served.
|
|
74
|
-
*
|
|
75
|
-
* @type {boolean}
|
|
76
|
-
* @access protected
|
|
77
|
-
* @ignore
|
|
78
|
-
*/
|
|
79
|
-
this._ready = true;
|
|
80
|
-
// If an `HTMLGenerator` service was specified...
|
|
81
|
-
if (this._htmlGenerator) {
|
|
82
|
-
// ...get the name of the file from that service.
|
|
83
|
-
this._file = this._htmlGenerator.getFile();
|
|
84
|
-
/**
|
|
85
|
-
* Mark the `_ready` flag as `false` as this service needs to wait for the generator to
|
|
86
|
-
* create the file.
|
|
87
|
-
*/
|
|
88
|
-
this._ready = false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns the Express middleware that serves the HTML file.
|
|
93
|
-
*
|
|
94
|
-
* @returns {ExpressMiddleware}
|
|
95
|
-
*/
|
|
96
|
-
middleware() {
|
|
97
|
-
return (req, res, next) => {
|
|
98
|
-
// If `_ready` is `false`
|
|
99
|
-
if (!this._ready) {
|
|
100
|
-
/**
|
|
101
|
-
* It means that it's using the `HTMLGenerator` service, so it
|
|
102
|
-
* calls the method that will notify this service when the file has been created and is
|
|
103
|
-
* ready to be loaded.
|
|
104
|
-
*/
|
|
105
|
-
this._htmlGenerator
|
|
106
|
-
.whenReady()
|
|
107
|
-
.then(() => {
|
|
108
|
-
// The file is ready to use, so mark the `_ready` flag as `true`.
|
|
109
|
-
this._ready = true;
|
|
110
|
-
// Serve the file.
|
|
111
|
-
this._sendHTML(res, next);
|
|
112
|
-
})
|
|
113
|
-
.catch((error) => {
|
|
114
|
-
// Something happened while generating the file, send the error the next middlware.
|
|
115
|
-
next(error);
|
|
116
|
-
});
|
|
117
|
-
} else {
|
|
118
|
-
/**
|
|
119
|
-
* If `_ready` is `true` it means that the `HTMLGenerator` has already created the file on
|
|
120
|
-
* a previous request or it was never specified, so just serve the file.
|
|
121
|
-
*/
|
|
122
|
-
this._sendHTML(res, next);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* The name of the file to serve.
|
|
128
|
-
*
|
|
129
|
-
* @type {string}
|
|
130
|
-
*/
|
|
131
|
-
get file() {
|
|
132
|
-
return this._file;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Serves the file on the response.
|
|
136
|
-
*
|
|
137
|
-
* @param {ExpressResponse} res The server response.
|
|
138
|
-
* @param {ExpressNext} next The functino to call the next middleware.
|
|
139
|
-
* @access protected
|
|
140
|
-
* @ignore
|
|
141
|
-
*/
|
|
142
|
-
_sendHTML(res, next) {
|
|
143
|
-
res.setHeader('Content-Type', mime.getType('html'));
|
|
144
|
-
this._sendFile(res, this._file, next);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* A middleware for showing an `index.html` file.
|
|
149
|
-
*
|
|
150
|
-
* @type {MiddlewareCreator<ShowHTMLMiddlewareOptions>}
|
|
151
|
-
* @parent module:middlewares
|
|
152
|
-
*/
|
|
153
|
-
const showHTML = middlewareCreator((options = {}) => (app) => {
|
|
154
|
-
const htmlGeneratorServiceName =
|
|
155
|
-
typeof options.htmlGenerator === 'undefined'
|
|
156
|
-
? 'htmlGenerator'
|
|
157
|
-
: options.htmlGenerator;
|
|
158
|
-
|
|
159
|
-
return new ShowHTML(
|
|
160
|
-
app.get('sendFile'),
|
|
161
|
-
options.file,
|
|
162
|
-
htmlGeneratorServiceName ? app.try(htmlGeneratorServiceName) : null,
|
|
163
|
-
).middleware();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
module.exports.ShowHTML = ShowHTML;
|
|
167
|
-
module.exports.showHTML = showHTML;
|
package/src/middlewares/index.js
DELETED