jimpex 7.0.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/LICENSE +1 -1
- package/README.md +446 -434
- package/dist/app/index.d.ts +13 -0
- package/dist/app/index.js +19 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/jimpex.d.ts +13 -0
- package/dist/app/jimpex.js +440 -0
- package/dist/app/jimpex.js.map +1 -0
- package/dist/controllers/common/config.d.ts +78 -0
- package/dist/controllers/common/config.js +89 -0
- package/dist/controllers/common/config.js.map +1 -0
- package/dist/controllers/common/health.d.ts +82 -0
- package/dist/controllers/common/health.js +97 -0
- package/dist/controllers/common/health.js.map +1 -0
- package/dist/controllers/common/index.d.ts +21 -0
- package/dist/controllers/common/index.js +21 -0
- package/dist/controllers/common/index.js.map +1 -0
- package/dist/controllers/common/statics.d.ts +215 -0
- package/dist/controllers/common/statics.js +202 -0
- package/dist/controllers/common/statics.js.map +1 -0
- package/dist/controllers/index.d.ts +24 -0
- package/dist/controllers/index.js +20 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/utils/gateway.d.ts +724 -0
- package/dist/controllers/utils/gateway.js +425 -0
- package/dist/controllers/utils/gateway.js.map +1 -0
- package/dist/controllers/utils/index.d.ts +16 -0
- package/dist/controllers/utils/index.js +19 -0
- package/dist/controllers/utils/index.js.map +1 -0
- package/dist/esm/app/index.js +2 -0
- package/dist/esm/app/index.js.map +1 -0
- package/dist/esm/app/jimpex.js +415 -0
- package/dist/esm/app/jimpex.js.map +1 -0
- package/dist/esm/chunk-T2T6Q22Z.js +11 -0
- package/dist/esm/chunk-T2T6Q22Z.js.map +1 -0
- package/dist/esm/controllers/common/config.js +62 -0
- package/dist/esm/controllers/common/config.js.map +1 -0
- package/dist/esm/controllers/common/health.js +70 -0
- package/dist/esm/controllers/common/health.js.map +1 -0
- package/dist/esm/controllers/common/index.js +4 -0
- package/dist/esm/controllers/common/index.js.map +1 -0
- package/dist/esm/controllers/common/statics.js +173 -0
- package/dist/esm/controllers/common/statics.js.map +1 -0
- package/dist/esm/controllers/index.js +3 -0
- package/dist/esm/controllers/index.js.map +1 -0
- package/dist/esm/controllers/utils/gateway.js +404 -0
- package/dist/esm/controllers/utils/gateway.js.map +1 -0
- package/dist/esm/controllers/utils/index.js +2 -0
- package/dist/esm/controllers/utils/index.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/middlewares/common/errorHandler.js +92 -0
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
- package/dist/esm/middlewares/common/forceHTTPS.js +41 -0
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/esm/middlewares/common/hsts.js +53 -0
- package/dist/esm/middlewares/common/hsts.js.map +1 -0
- package/dist/esm/middlewares/common/index.js +4 -0
- package/dist/esm/middlewares/common/index.js.map +1 -0
- package/dist/esm/middlewares/html/fastHTML.js +104 -0
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
- package/dist/esm/middlewares/html/index.js +3 -0
- package/dist/esm/middlewares/html/index.js.map +1 -0
- package/dist/esm/middlewares/html/showHTML.js +68 -0
- package/dist/esm/middlewares/html/showHTML.js.map +1 -0
- package/dist/esm/middlewares/index.js +4 -0
- package/dist/esm/middlewares/index.js.map +1 -0
- package/dist/esm/middlewares/utils/index.js +2 -0
- package/dist/esm/middlewares/utils/index.js.map +1 -0
- package/dist/esm/middlewares/utils/versionValidator.js +101 -0
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/esm/services/common/appError.js +52 -0
- package/dist/esm/services/common/appError.js.map +1 -0
- package/dist/esm/services/common/httpError.js +19 -0
- package/dist/esm/services/common/httpError.js.map +1 -0
- package/dist/esm/services/common/index.js +17 -0
- package/dist/esm/services/common/index.js.map +1 -0
- package/dist/esm/services/common/sendFile.js +27 -0
- package/dist/esm/services/common/sendFile.js.map +1 -0
- package/dist/esm/services/frontend/frontendFs.js +38 -0
- package/dist/esm/services/frontend/frontendFs.js.map +1 -0
- package/dist/esm/services/frontend/index.js +11 -0
- package/dist/esm/services/frontend/index.js.map +1 -0
- package/dist/esm/services/html/htmlGenerator.js +144 -0
- package/dist/esm/services/html/htmlGenerator.js.map +1 -0
- package/dist/esm/services/html/index.js +11 -0
- package/dist/esm/services/html/index.js.map +1 -0
- package/dist/esm/services/http/apiClient.js +71 -0
- package/dist/esm/services/http/apiClient.js.map +1 -0
- package/dist/esm/services/http/http.js +125 -0
- package/dist/esm/services/http/http.js.map +1 -0
- package/dist/esm/services/http/index.js +17 -0
- package/dist/esm/services/http/index.js.map +1 -0
- package/dist/esm/services/http/responsesBuilder.js +105 -0
- package/dist/esm/services/http/responsesBuilder.js.map +1 -0
- package/dist/esm/services/index.js +6 -0
- package/dist/esm/services/index.js.map +1 -0
- package/dist/esm/services/utils/ensureBearerToken.js +78 -0
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/esm/services/utils/index.js +11 -0
- package/dist/esm/services/utils/index.js.map +1 -0
- package/dist/esm/types/events.js +1 -0
- package/dist/esm/types/events.js.map +1 -0
- package/dist/esm/types/express.js +1 -0
- package/dist/esm/types/express.js.map +1 -0
- package/dist/esm/types/http.js +1 -0
- package/dist/esm/types/http.js.map +1 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/options.js.map +1 -0
- package/dist/esm/types/utils.js +1 -0
- package/dist/esm/types/utils.js.map +1 -0
- package/dist/esm/types/wootils.js +1 -0
- package/dist/esm/types/wootils.js.map +1 -0
- package/dist/esm/utils/fns/index.js +5 -0
- package/dist/esm/utils/fns/index.js.map +1 -0
- package/dist/esm/utils/fns/others.js +6 -0
- package/dist/esm/utils/fns/others.js.map +1 -0
- package/dist/esm/utils/fns/routes.js +25 -0
- package/dist/esm/utils/fns/routes.js.map +1 -0
- package/dist/esm/utils/fns/statuses.js +6 -0
- package/dist/esm/utils/fns/statuses.js.map +1 -0
- package/dist/esm/utils/fns/text.js +6 -0
- package/dist/esm/utils/fns/text.js.map +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/wrappers.js +41 -0
- package/dist/esm/utils/wrappers.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jimpex-7eaee271.d.ts +1278 -0
- package/dist/middlewares/common/errorHandler.d.ts +131 -0
- package/dist/middlewares/common/errorHandler.js +119 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +68 -0
- package/dist/middlewares/common/forceHTTPS.js +68 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/middlewares/common/hsts.d.ts +109 -0
- package/dist/middlewares/common/hsts.js +80 -0
- package/dist/middlewares/common/hsts.js.map +1 -0
- package/dist/middlewares/common/index.d.ts +21 -0
- package/dist/middlewares/common/index.js +21 -0
- package/dist/middlewares/common/index.js.map +1 -0
- package/dist/middlewares/html/fastHTML.d.ts +180 -0
- package/dist/middlewares/html/fastHTML.js +131 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -0
- package/dist/middlewares/html/index.d.ts +21 -0
- package/dist/middlewares/html/index.js +20 -0
- package/dist/middlewares/html/index.js.map +1 -0
- package/dist/middlewares/html/showHTML.d.ts +127 -0
- package/dist/middlewares/html/showHTML.js +95 -0
- package/dist/middlewares/html/showHTML.js.map +1 -0
- package/dist/middlewares/index.d.ts +30 -0
- package/dist/middlewares/index.js +21 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/utils/index.d.ts +19 -0
- package/dist/middlewares/utils/index.js +19 -0
- package/dist/middlewares/utils/index.js.map +1 -0
- package/dist/middlewares/utils/versionValidator.d.ts +214 -0
- package/dist/middlewares/utils/versionValidator.js +128 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/services/common/appError.d.ts +138 -0
- package/dist/services/common/appError.js +80 -0
- package/dist/services/common/appError.js.map +1 -0
- package/dist/services/common/httpError.d.ts +79 -0
- package/dist/services/common/httpError.js +44 -0
- package/dist/services/common/httpError.js.map +1 -0
- package/dist/services/common/index.d.ts +47 -0
- package/dist/services/common/index.js +41 -0
- package/dist/services/common/index.js.map +1 -0
- package/dist/services/common/sendFile.d.ts +102 -0
- package/dist/services/common/sendFile.js +51 -0
- package/dist/services/common/sendFile.js.map +1 -0
- package/dist/services/frontend/frontendFs.d.ts +96 -0
- package/dist/services/frontend/frontendFs.js +71 -0
- package/dist/services/frontend/frontendFs.js.map +1 -0
- package/dist/services/frontend/index.d.ts +40 -0
- package/dist/services/frontend/index.js +35 -0
- package/dist/services/frontend/index.js.map +1 -0
- package/dist/services/html/htmlGenerator.d.ts +237 -0
- package/dist/services/html/htmlGenerator.js +171 -0
- package/dist/services/html/htmlGenerator.js.map +1 -0
- package/dist/services/html/index.d.ts +43 -0
- package/dist/services/html/index.js +35 -0
- package/dist/services/html/index.js.map +1 -0
- package/dist/services/http/apiClient.d.ts +169 -0
- package/dist/services/http/apiClient.js +96 -0
- package/dist/services/http/apiClient.js.map +1 -0
- package/dist/services/http/http.d.ts +175 -0
- package/dist/services/http/http.js +158 -0
- package/dist/services/http/http.js.map +1 -0
- package/dist/services/http/index.d.ts +50 -0
- package/dist/services/http/index.js +41 -0
- package/dist/services/http/index.js.map +1 -0
- package/dist/services/http/responsesBuilder.d.ts +178 -0
- package/dist/services/http/responsesBuilder.js +132 -0
- package/dist/services/http/responsesBuilder.js.map +1 -0
- package/dist/services/index.d.ts +33 -0
- package/dist/services/index.js +23 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/utils/ensureBearerToken.d.ts +157 -0
- package/dist/services/utils/ensureBearerToken.js +105 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/services/utils/index.d.ts +43 -0
- package/dist/services/utils/index.js +35 -0
- package/dist/services/utils/index.js.map +1 -0
- package/dist/types/events.d.ts +13 -0
- package/dist/types/events.js +17 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/express.d.ts +10 -0
- package/dist/types/express.js +17 -0
- package/dist/types/express.js.map +1 -0
- package/dist/types/http.d.ts +79 -0
- package/dist/types/http.js +17 -0
- package/dist/types/http.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.ts +13 -0
- package/dist/types/options.js +17 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/utils.d.ts +48 -0
- package/dist/types/utils.js +17 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/types/wootils.d.ts +4 -0
- package/dist/types/wootils.js +17 -0
- package/dist/types/wootils.js.map +1 -0
- package/dist/utils/fns/index.d.ts +5 -0
- package/dist/utils/fns/index.js +22 -0
- package/dist/utils/fns/index.js.map +1 -0
- package/dist/utils/fns/others.d.ts +17 -0
- package/dist/utils/fns/others.js +29 -0
- package/dist/utils/fns/others.js.map +1 -0
- package/dist/utils/fns/routes.d.ts +39 -0
- package/dist/utils/fns/routes.js +51 -0
- package/dist/utils/fns/routes.js.map +1 -0
- package/dist/utils/fns/statuses.d.ts +45 -0
- package/dist/utils/fns/statuses.js +35 -0
- package/dist/utils/fns/statuses.js.map +1 -0
- package/dist/utils/fns/text.d.ts +9 -0
- package/dist/utils/fns/text.js +29 -0
- package/dist/utils/fns/text.js.map +1 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/wrappers.d.ts +13 -0
- package/dist/utils/wrappers.js +68 -0
- package/dist/utils/wrappers.js.map +1 -0
- package/examples/basic/404.html +12 -0
- package/examples/basic/README.md +30 -0
- package/examples/basic/app.ts +18 -0
- package/examples/basic/controller.ts +45 -0
- package/examples/basic/index.ts +19 -0
- package/examples/basic/middleware.ts +13 -0
- package/examples/basic/service.ts +11 -0
- package/package.json +59 -38
- package/src/app/index.ts +1 -0
- package/src/app/jimpex.ts +743 -0
- package/src/controllers/common/config.ts +115 -0
- package/src/controllers/common/health.ts +128 -0
- package/src/controllers/common/index.ts +3 -0
- package/src/controllers/common/statics.ts +380 -0
- package/src/controllers/index.ts +2 -0
- package/src/controllers/utils/gateway.ts +1186 -0
- package/src/controllers/utils/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/middlewares/common/errorHandler.ts +203 -0
- package/src/middlewares/common/forceHTTPS.ts +83 -0
- package/src/middlewares/common/hsts.ts +135 -0
- package/src/middlewares/common/index.ts +3 -0
- package/src/middlewares/html/fastHTML.ts +255 -0
- package/src/middlewares/html/index.ts +2 -0
- package/src/middlewares/html/showHTML.ts +165 -0
- package/src/middlewares/index.ts +3 -0
- package/src/middlewares/utils/index.ts +1 -0
- package/src/middlewares/utils/versionValidator.ts +289 -0
- package/src/services/common/appError.ts +158 -0
- package/src/services/common/httpError.ts +74 -0
- package/src/services/common/index.ts +29 -0
- package/src/services/common/sendFile.ts +106 -0
- package/src/services/frontend/frontendFs.ts +101 -0
- package/src/services/frontend/index.ts +21 -0
- package/src/services/html/htmlGenerator.ts +356 -0
- package/src/services/html/index.ts +21 -0
- package/src/services/http/apiClient.ts +221 -0
- package/src/services/http/http.ts +286 -0
- package/src/services/http/index.ts +29 -0
- package/src/services/http/responsesBuilder.ts +265 -0
- package/src/services/index.ts +5 -0
- package/src/services/utils/ensureBearerToken.ts +202 -0
- package/src/services/utils/index.ts +21 -0
- package/src/types/events.ts +303 -0
- package/src/types/express.ts +21 -0
- package/src/types/http.ts +77 -0
- package/src/types/index.ts +6 -0
- package/src/types/options.ts +248 -0
- package/src/types/utils.ts +52 -0
- package/src/types/wootils.ts +4 -0
- package/src/utils/fns/index.ts +4 -0
- package/src/utils/fns/others.ts +15 -0
- package/src/utils/fns/routes.ts +64 -0
- package/src/utils/fns/statuses.ts +44 -0
- package/src/utils/fns/text.ts +8 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/wrappers.ts +537 -0
- package/tsconfig.json +5 -8
- package/tsup.config.ts +10 -0
- package/src/app/index.js +0 -692
- package/src/constants/eventNames.js +0 -48
- package/src/constants/index.js +0 -7
- package/src/controllers/common/configuration.js +0 -116
- package/src/controllers/common/health.js +0 -79
- package/src/controllers/common/index.js +0 -7
- package/src/controllers/common/statics.js +0 -336
- package/src/controllers/index.js +0 -9
- package/src/controllers/utils/gateway.js +0 -1039
- package/src/controllers/utils/index.js +0 -3
- package/src/index.js +0 -30
- package/src/middlewares/common/errorHandler.js +0 -185
- package/src/middlewares/common/forceHTTPS.js +0 -80
- package/src/middlewares/common/hsts.js +0 -122
- package/src/middlewares/common/index.js +0 -7
- package/src/middlewares/html/fastHTML.js +0 -298
- package/src/middlewares/html/index.js +0 -5
- package/src/middlewares/html/showHTML.js +0 -167
- package/src/middlewares/index.js +0 -11
- package/src/middlewares/utils/index.js +0 -3
- package/src/middlewares/utils/versionValidator.js +0 -261
- package/src/services/common/appError.js +0 -136
- package/src/services/common/httpError.js +0 -60
- package/src/services/common/index.js +0 -25
- package/src/services/common/sendFile.js +0 -68
- package/src/services/frontend/frontendFs.js +0 -85
- package/src/services/frontend/index.js +0 -17
- package/src/services/html/htmlGenerator.js +0 -391
- package/src/services/html/index.js +0 -17
- package/src/services/http/apiClient.js +0 -148
- package/src/services/http/http.js +0 -256
- package/src/services/http/index.js +0 -25
- package/src/services/http/responsesBuilder.js +0 -193
- package/src/services/index.js +0 -15
- package/src/services/utils/ensureBearerToken.js +0 -147
- package/src/services/utils/index.js +0 -19
- package/src/types.js +0 -377
- package/src/utils/functions.js +0 -78
- package/src/utils/wrappers.js +0 -131
- package/types/app/index.d.ts +0 -417
- package/types/constants/eventNames.d.ts +0 -93
- package/types/constants/index.d.ts +0 -2
- package/types/controllers/common/configuration.d.ts +0 -71
- package/types/controllers/common/health.d.ts +0 -55
- package/types/controllers/common/index.d.ts +0 -4
- package/types/controllers/common/statics.d.ts +0 -271
- package/types/controllers/index.d.ts +0 -3
- package/types/controllers/utils/gateway.d.ts +0 -947
- package/types/controllers/utils/index.d.ts +0 -2
- package/types/index.d.ts +0 -15
- package/types/middlewares/common/errorHandler.d.ts +0 -143
- package/types/middlewares/common/forceHTTPS.d.ts +0 -64
- package/types/middlewares/common/hsts.d.ts +0 -111
- package/types/middlewares/common/index.d.ts +0 -4
- package/types/middlewares/html/fastHTML.d.ts +0 -238
- package/types/middlewares/html/index.d.ts +0 -3
- package/types/middlewares/html/showHTML.d.ts +0 -128
- package/types/middlewares/index.d.ts +0 -4
- package/types/middlewares/utils/index.d.ts +0 -2
- package/types/middlewares/utils/versionValidator.d.ts +0 -247
- package/types/services/common/appError.d.ts +0 -89
- package/types/services/common/httpError.d.ts +0 -37
- package/types/services/common/index.d.ts +0 -18
- package/types/services/common/sendFile.d.ts +0 -56
- package/types/services/frontend/frontendFs.d.ts +0 -72
- package/types/services/frontend/index.d.ts +0 -3
- package/types/services/html/htmlGenerator.d.ts +0 -298
- package/types/services/html/index.d.ts +0 -3
- package/types/services/http/apiClient.d.ts +0 -141
- package/types/services/http/http.d.ts +0 -159
- package/types/services/http/index.d.ts +0 -18
- package/types/services/http/responsesBuilder.d.ts +0 -140
- package/types/services/index.d.ts +0 -6
- package/types/services/utils/ensureBearerToken.d.ts +0 -137
- package/types/services/utils/index.d.ts +0 -16
- package/types/types.d.ts +0 -280
- package/types/utils/functions.d.ts +0 -55
- package/types/utils/wrappers.d.ts +0 -127
package/README.md
CHANGED
|
@@ -2,148 +2,229 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/homer0/jimpex/actions?query=workflow%3ATest)
|
|
4
4
|
[](https://coveralls.io/github/homer0/jimpex?branch=main)
|
|
5
|
-
|
|
6
|
-
[](https://david-dm.org/homer0/jimpex)
|
|
5
|
+

|
|
7
6
|
|
|
8
7
|
Express as dependency injection container.
|
|
9
8
|
|
|
10
|
-
Jimpex is an implementation of [Express](https://expressjs.com), one of the most popular web frameworks for Node, using [Jimple](https://github.com/fjorgemota/jimple), a Javascript port of [Pimple](https://
|
|
9
|
+
Jimpex is an implementation of [Express](https://expressjs.com), one of the most popular web frameworks for Node, using [Jimple](https://github.com/fjorgemota/jimple), a Javascript port of [Pimple](https://github.com/silexphp/Pimple) dependency injection container.
|
|
10
|
+
|
|
11
|
+
> ⚠️ If you want to upgrade to v8, please read the [migration guide](https://github.com/homer0/jimpex/blob/main/documents/migration-v8.md).
|
|
12
|
+
|
|
13
|
+
- [🍿 Usage](#🍿-usage)
|
|
14
|
+
- [🎨 Creating your app](#🎨-creating-your-app)
|
|
15
|
+
- [🤖 Boot](#🤖-boot)
|
|
16
|
+
- [⚙️ Options and configuration](#⚙️-options-and-configuration)
|
|
17
|
+
- [Options](#options)
|
|
18
|
+
- [Configuration](#configuration)
|
|
19
|
+
- [🚀 Starting your app](#🚀-starting-the-app)
|
|
20
|
+
- [✅ HTTPS](#✅-https)
|
|
21
|
+
- [HTTP2](#http2)
|
|
22
|
+
- [🛠 Services](#🛠-services)
|
|
23
|
+
- [Configurable services](#configurable-services)
|
|
24
|
+
- [🚦 Controllers](#🚦-controller)
|
|
25
|
+
- [Configurable controllers](#configurable-controllers)
|
|
26
|
+
- [Controllers with services](#controllers-with-services)
|
|
27
|
+
- [⚡️ Middlewares](#⚡️-middlewares)
|
|
28
|
+
- [Configurable middlewares](#configurable-middlewares)
|
|
29
|
+
- [Middlewares with services](#middlewares-with-services)
|
|
30
|
+
- [💪 TypeScript](#💪-typescript)
|
|
31
|
+
- [🤞 Examples](#🤞-examples)
|
|
32
|
+
- [🤘 Development](#development)
|
|
33
|
+
- [NPM scripts](#npm-scripts)
|
|
34
|
+
- [Repository hooks](#repository-hooks)
|
|
35
|
+
- [Commits conventions](#commits-conventions)
|
|
36
|
+
- [Releases](#releases)
|
|
37
|
+
- [Testing](#testing)
|
|
38
|
+
- [Code linting and formatting](#code-linting-and-formatting)
|
|
39
|
+
- [Documentation](#documentation)
|
|
40
|
+
- [👀 Motivation](#👀-motivation)
|
|
41
|
+
|
|
42
|
+
## 🍿 Usage
|
|
43
|
+
|
|
44
|
+
### 🎨 Creating your app
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { jimpex } from 'jimpex';
|
|
11
48
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
49
|
+
const app = jimpex();
|
|
50
|
+
app.set('something', () => new Something());
|
|
51
|
+
app.mount('/hello', (req, res) => res.send('Hello World!'));
|
|
52
|
+
app.listen(2509, () => {
|
|
53
|
+
console.log('The app is running!');
|
|
54
|
+
});
|
|
55
|
+
```
|
|
15
56
|
|
|
16
|
-
|
|
57
|
+
That's all: you create the app, register/set your dependencies, and mount your routes.
|
|
17
58
|
|
|
18
|
-
|
|
59
|
+
Alternatively, you could import the class, subclass it, and make use of the "life cycle" methods to configure it:
|
|
19
60
|
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
// OR import { Jimpex } from 'jimpex/esm';
|
|
61
|
+
```ts
|
|
62
|
+
import { Jimpex } from 'jimpex';
|
|
23
63
|
|
|
24
64
|
class MyApp extends Jimpex {
|
|
25
65
|
boot() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.mount(...);
|
|
66
|
+
this.set('something', () => new Something());
|
|
67
|
+
app.mount('/hello', (req, res) => res.send('Hello World!'));
|
|
29
68
|
}
|
|
30
69
|
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
The class constructor has two parameters:
|
|
34
70
|
|
|
35
|
-
|
|
36
|
-
(
|
|
71
|
+
const app = new MyApp();
|
|
72
|
+
app.listen(2509, () => {
|
|
73
|
+
console.log('The app is running!');
|
|
74
|
+
});
|
|
37
75
|
```
|
|
38
76
|
|
|
39
|
-
|
|
40
|
-
2. The default configuration, in case you don't want Jimpex to try loading an external configuration file.
|
|
77
|
+
### 🤖 Boot
|
|
41
78
|
|
|
42
|
-
|
|
79
|
+
The `boot` method gets called right from the constructor, when the `boot` option is set to `true` (its default value), and the idea is for you to use it to add all your customizations (as seen in the example above).
|
|
43
80
|
|
|
44
|
-
|
|
81
|
+
Like `boot`, there's another "helper method" that you can use to register your dependencies: `_init`; the difference is that `_init` gets called from the constructor before the `boot` options gets validated. This allows you to create scenarios in which you could register some resources on `_init`, disable the call to `boot`, overwrite what you set on `_init`, and manually call `boot`:
|
|
45
82
|
|
|
46
|
-
```
|
|
83
|
+
```ts
|
|
47
84
|
class MyApp extends Jimpex {
|
|
48
85
|
_init() {
|
|
49
|
-
this.set('
|
|
86
|
+
this.set('message', 'Hello Charo!');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
boot() {
|
|
90
|
+
app.mount('/hello', (req, res) => res.send(this.get('message')));
|
|
50
91
|
}
|
|
51
92
|
}
|
|
93
|
+
|
|
94
|
+
const app = new MyApp({ boot: false });
|
|
95
|
+
app.set('message', 'Hello Pili!');
|
|
96
|
+
app.boot();
|
|
52
97
|
```
|
|
53
98
|
|
|
54
|
-
|
|
99
|
+
Now, this may look like an unnecessary feature, but if you consider the possiblity of different entry points based on environment, maybe to enable debugging tools on dev, this becomes really useful.
|
|
55
100
|
|
|
56
|
-
|
|
101
|
+
### ⚙️ Options and configuration
|
|
57
102
|
|
|
58
|
-
|
|
59
|
-
const MyApp = require('...');
|
|
103
|
+
On Jimpex, you have two sets of "settings": the options, which are in the code when you create the application; and the configuration, which may be related to the environment in which the application is running.
|
|
60
104
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
105
|
+
#### Options
|
|
106
|
+
|
|
107
|
+
You can read all about the different options in [its own documentation](https://github.com/homer0/jimpex/blob/main/documents/options.md), but they're more related to the application capabilities. For example:
|
|
108
|
+
|
|
109
|
+
- Whether or not to call `boot`.
|
|
110
|
+
- Whether or not Express should remove the `x-powered-by` header.
|
|
111
|
+
- Which env var to check for the environment configuration (you'll see more about this in a sec).
|
|
112
|
+
|
|
113
|
+
And depending on how you defined your application, you have two ways to customize the options.
|
|
114
|
+
|
|
115
|
+
First, if you used the function, you can just send them as a parameter:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { jimpex } from 'jimpex';
|
|
119
|
+
|
|
120
|
+
const app = jimpex({
|
|
121
|
+
boot: false,
|
|
122
|
+
express: {
|
|
123
|
+
disableXPoweredBy: true,
|
|
124
|
+
},
|
|
125
|
+
config: {
|
|
126
|
+
environmentVariable: 'NODE_ENV',
|
|
127
|
+
},
|
|
128
|
+
});
|
|
65
129
|
```
|
|
66
130
|
|
|
67
|
-
|
|
131
|
+
And yes, you could also use this approach with the class, as both the function and the class constructor share the same parameters, but if you want to already define your options inside your subclass, there's a _protected_ helper for it: `_initOptions`.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { Jimpex } from 'jimpex';
|
|
68
135
|
|
|
69
|
-
```js
|
|
70
136
|
class MyApp extends Jimpex {
|
|
71
137
|
_initOptions() {
|
|
72
138
|
return {
|
|
73
|
-
|
|
74
|
-
|
|
139
|
+
boot: false,
|
|
140
|
+
express: {
|
|
141
|
+
disableXPoweredBy: true,
|
|
142
|
+
},
|
|
143
|
+
config: {
|
|
144
|
+
environmentVariable: 'NODE_ENV',
|
|
75
145
|
},
|
|
76
146
|
};
|
|
77
147
|
}
|
|
78
148
|
}
|
|
79
149
|
```
|
|
80
150
|
|
|
81
|
-
|
|
151
|
+
The advantage of `_initOptions` is not only that you don't need to overwrite the constructor, but that you can still receive the options from the constructor, and Jimpex will automatically deep merge the ones on `_initOptions` on top of them.
|
|
82
152
|
|
|
83
|
-
|
|
153
|
+
#### Configuration
|
|
84
154
|
|
|
85
|
-
|
|
155
|
+
These are the settings that are more related to the runtime, and that can change depending on the environment. The most basic example of a "configuration setting" would be the port in which the application runs: you could run it on local env in 3000, and on production in 80 (or 443).
|
|
86
156
|
|
|
87
|
-
|
|
157
|
+
While the configuration is more easily managed with external (config) files, you could also send it in the options:
|
|
88
158
|
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
// OR import { jimpex } from 'jimpex/esm';
|
|
159
|
+
```ts
|
|
160
|
+
import { jimpex } from 'jimpex';
|
|
92
161
|
|
|
93
|
-
const app = jimpex(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
162
|
+
const app = jimpex({
|
|
163
|
+
config: {
|
|
164
|
+
default: {
|
|
165
|
+
port: 3000,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
99
169
|
|
|
100
|
-
|
|
170
|
+
// or
|
|
101
171
|
|
|
102
|
-
|
|
103
|
-
|
|
172
|
+
const app2 = jimpex(
|
|
173
|
+
{ someOption: false },
|
|
174
|
+
{
|
|
175
|
+
port: 3000,
|
|
176
|
+
},
|
|
177
|
+
);
|
|
104
178
|
```
|
|
105
179
|
|
|
106
|
-
|
|
107
|
-
2. The default configuration. The big difference here is that, even if you send `null`, Jimpex won't try to load an external configuration file.
|
|
180
|
+
You can use the option `config.default`, or just the second parameter of both the function and the class.
|
|
108
181
|
|
|
109
|
-
|
|
182
|
+
> ⚠️ If you don't configure the `port` and call `start()`, the application will throw an error.
|
|
110
183
|
|
|
111
|
-
|
|
184
|
+
That's the basic usage, but as mentioned before, the configuration is more easily managed with external files: when loading the configuration, which happens when the server starts, it will try to look for a file `config/app.config.js`, and if it exists, it will set whatever it (default) exports as the configuration.
|
|
112
185
|
|
|
113
|
-
|
|
186
|
+
So, we could write the configuration from the example above and use it like this:
|
|
114
187
|
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
|
|
188
|
+
```ts
|
|
189
|
+
// config/app.config.js
|
|
190
|
+
export default {
|
|
191
|
+
port: 3000,
|
|
118
192
|
};
|
|
119
|
-
```
|
|
120
193
|
|
|
121
|
-
|
|
194
|
+
// src/index.js
|
|
195
|
+
import { jimpex } from 'jimpex';
|
|
122
196
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
```js
|
|
126
|
-
new MyApp({ ... }, { port: 2509 });
|
|
127
|
-
// OR
|
|
128
|
-
jimpex({ ... }, { port: 2509 });
|
|
197
|
+
const app = jimpex();
|
|
198
|
+
app.start();
|
|
129
199
|
```
|
|
130
200
|
|
|
131
|
-
Now,
|
|
201
|
+
Now, the really great feature about the config files, is that you could extend them and manage which one gets loaded depending on the environment: When loading the configuration, Jimpex will check the value of the environment variable `CONFIG` and try to load a config file `config/app.config.${CONFIG}.js`. For example:
|
|
132
202
|
|
|
133
|
-
|
|
134
|
-
|
|
203
|
+
You could have the default configuration with the port set to `3000`, and a "staging" configuration with the port set to `80`.
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
// config/app.config.js
|
|
207
|
+
export default {
|
|
208
|
+
port: 3000,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// config/app.config.staging.js
|
|
212
|
+
export default {
|
|
213
|
+
port: 80,
|
|
214
|
+
};
|
|
135
215
|
```
|
|
136
216
|
|
|
137
|
-
|
|
217
|
+
And if `CONFIG` is set to `staging` when the application starts, the staging configuration will be loaded.
|
|
138
218
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
219
|
+
Finally, you can access the configuration settings with the `config` service:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
const port = app.get('config').get('port');
|
|
142
223
|
```
|
|
143
224
|
|
|
144
|
-
|
|
225
|
+
> You can read more about the options for the configuration service in the [options documentation](https://github.com/homer0/jimpex/blob/main/documents/options.md), but it's basically an implementation of [`@homer0/simple-config`](https://www.npmjs.com/package/@homer0/simple-config).
|
|
145
226
|
|
|
146
|
-
|
|
227
|
+
### 🚀 Starting the app
|
|
147
228
|
|
|
148
229
|
```js
|
|
149
230
|
app.listen(2509, () => {
|
|
@@ -168,46 +249,39 @@ app.stop();
|
|
|
168
249
|
// Done, the app is not longer running.
|
|
169
250
|
```
|
|
170
251
|
|
|
171
|
-
### HTTPS
|
|
252
|
+
### ✅ HTTPS
|
|
172
253
|
|
|
173
|
-
|
|
254
|
+
HTTPS is enabled via configuration, not options, just like the application port:
|
|
174
255
|
|
|
175
|
-
```
|
|
176
|
-
|
|
256
|
+
```ts
|
|
257
|
+
// config/app.config.js
|
|
258
|
+
export default {
|
|
177
259
|
port: 2509,
|
|
178
260
|
https: {
|
|
179
261
|
enabled: true,
|
|
180
262
|
credentials: {
|
|
181
|
-
cert: 'cert-file',
|
|
182
|
-
key: 'key-file',
|
|
263
|
+
cert: '...cert-file',
|
|
264
|
+
key: '...key-file',
|
|
183
265
|
},
|
|
184
266
|
},
|
|
185
267
|
};
|
|
186
268
|
```
|
|
187
269
|
|
|
188
|
-
By default, Jimpex will look for those files relative to the project root directory, but you can change so it will look on a path relative to the directory where the application executable is located
|
|
270
|
+
By default, Jimpex will look for those files relative to the project root directory, but you can change so it will look on a path relative to the directory where the application executable is located by setting `https.credentials.onHome` to `false`.
|
|
189
271
|
|
|
190
|
-
|
|
191
|
-
{
|
|
192
|
-
// ...
|
|
193
|
-
credentials: {
|
|
194
|
-
onHome: false,
|
|
195
|
-
cert: 'cert-file',
|
|
196
|
-
key: 'key-file',
|
|
197
|
-
},
|
|
198
|
-
}
|
|
199
|
-
```
|
|
272
|
+
#### HTTP2
|
|
200
273
|
|
|
201
|
-
|
|
274
|
+
To enable [HTTP/2](https://en.wikipedia.org/wiki/HTTP/2), you MUST enable HTTPS first, and then just add a flag in the configuration:
|
|
202
275
|
|
|
203
|
-
```
|
|
204
|
-
|
|
276
|
+
```ts
|
|
277
|
+
// config/app.config.js
|
|
278
|
+
export default {
|
|
205
279
|
port: 2509,
|
|
206
280
|
https: {
|
|
207
281
|
enabled: true,
|
|
208
282
|
credentials: {
|
|
209
|
-
cert: 'cert-file',
|
|
210
|
-
key: 'key-file',
|
|
283
|
+
cert: '...cert-file',
|
|
284
|
+
key: '...key-file',
|
|
211
285
|
},
|
|
212
286
|
},
|
|
213
287
|
http2: {
|
|
@@ -216,543 +290,481 @@ module.exports = {
|
|
|
216
290
|
};
|
|
217
291
|
```
|
|
218
292
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
Under the hood, Jimpex uses [Spdy](https://yarnpkg.com/package/spdy) for the HTTP/2 support, and Spdy has custom options you can send in order to define how it will work; you can send options to Spdy by adding a `spdy` key inside the `http2` object:
|
|
293
|
+
Under the hood, Jimpex uses [Spdy](https://npmjs.com/package/spdy) for the HTTP/2 support, and Spdy has custom options you can send in order to define how it will work; you can send options to Spdy by adding a `spdy` key inside the `http2` object:
|
|
222
294
|
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
|
|
295
|
+
```ts
|
|
296
|
+
// config/app.config.js
|
|
297
|
+
export default {
|
|
298
|
+
port: 2509,
|
|
299
|
+
https: {
|
|
300
|
+
enabled: true,
|
|
301
|
+
credentials: {
|
|
302
|
+
cert: '...cert-file',
|
|
303
|
+
key: '...key-file',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
226
306
|
http2: {
|
|
227
307
|
enabled: true,
|
|
228
308
|
spdy: {
|
|
229
309
|
'x-forwarded-for': '127.0.0.1',
|
|
230
310
|
},
|
|
231
311
|
},
|
|
232
|
-
}
|
|
312
|
+
};
|
|
233
313
|
```
|
|
234
314
|
|
|
235
|
-
###
|
|
315
|
+
### 🛠 Services
|
|
236
316
|
|
|
237
|
-
|
|
317
|
+
This is the most-core functionality that Jimple, and Jimpex, provide. You can easily create providers for services/resources that you want to use in your application:
|
|
238
318
|
|
|
239
|
-
```
|
|
240
|
-
|
|
319
|
+
```ts
|
|
320
|
+
// src/my-service.js
|
|
321
|
+
import { provider } from 'jimpex';
|
|
241
322
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
323
|
+
export class MyService {
|
|
324
|
+
constructor(config) {
|
|
325
|
+
this.config = config;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
getMeThePort() {
|
|
329
|
+
return this.config.get('port');
|
|
330
|
+
}
|
|
245
331
|
}
|
|
246
332
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
app.set('myService', () => new MyService(
|
|
250
|
-
app.get('depOne'),
|
|
251
|
-
app.get('depTwo')
|
|
252
|
-
));
|
|
333
|
+
export const myService = provider((app) => {
|
|
334
|
+
app.set('myService', () => new MyService(app.get('config')));
|
|
253
335
|
});
|
|
254
|
-
|
|
255
|
-
// Export the service and its provider
|
|
256
|
-
module.exports.MyService = MyService;
|
|
257
|
-
module.exports.myService = myService;
|
|
258
336
|
```
|
|
259
337
|
|
|
260
|
-
>
|
|
261
|
-
> 2. That why of using `module.expots` is so the class can be imported on JSDoc comments.
|
|
338
|
+
> You could just export the provider, but I believe is a good practice to export both, in case another part of your app wants to extend the class and overwrite the service on the container.
|
|
262
339
|
|
|
263
|
-
|
|
340
|
+
The, on the app, you would simple `register` the provider:
|
|
264
341
|
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
|
|
342
|
+
```ts
|
|
343
|
+
import { Jimpex } from 'jimpex';
|
|
344
|
+
import { myService } from './my-service';
|
|
268
345
|
|
|
269
346
|
class MyApp extends Jimpex {
|
|
270
347
|
boot() {
|
|
271
|
-
...
|
|
272
348
|
this.register(myService);
|
|
273
349
|
}
|
|
274
350
|
}
|
|
275
351
|
```
|
|
276
352
|
|
|
277
|
-
Done, your service is now available.
|
|
353
|
+
Done, your service is now available in the container.
|
|
278
354
|
|
|
279
|
-
|
|
355
|
+
Jimpex already comes with a few built-in service providers ready to be used, and you can read about them on the [services document](https://github.com/homer0/jimpex/blob/main/documents/services.md).
|
|
280
356
|
|
|
281
|
-
|
|
357
|
+
##### Configurable services
|
|
282
358
|
|
|
283
|
-
|
|
284
|
-
|
|
359
|
+
Since the version of Jimple that Jimpex uses under the hood is [`@homer0/jimple`](https://www.npmjs.com/package/@homer0/jimple), my custom "fork", you can also create "configureable providers":
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
// src/my-service.js
|
|
363
|
+
import { providerCreator } from 'jimpex';
|
|
364
|
+
|
|
365
|
+
export class MyService {
|
|
366
|
+
constructor(config) {
|
|
367
|
+
this.config = config;
|
|
368
|
+
}
|
|
285
369
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
370
|
+
getMeThePort() {
|
|
371
|
+
return this.config.get('port');
|
|
372
|
+
}
|
|
289
373
|
}
|
|
290
374
|
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
app.set(
|
|
294
|
-
app.get('depOne'),
|
|
295
|
-
app.get('depTwo'),
|
|
296
|
-
settings
|
|
297
|
-
));
|
|
375
|
+
export const myService = providerCreator((options = {}) => (app) => {
|
|
376
|
+
const { serviceName = 'myService' } = options;
|
|
377
|
+
app.set(serviceName, () => new MyService(app.get('config')));
|
|
298
378
|
});
|
|
299
|
-
|
|
300
|
-
// Export the service and its provider
|
|
301
|
-
module.exports = {
|
|
302
|
-
MyService,
|
|
303
|
-
myService,
|
|
304
|
-
};
|
|
305
379
|
```
|
|
306
380
|
|
|
307
|
-
|
|
381
|
+
If you are thinking this is just a HOF, you are wrong. The "magic" of the creator version is that it can be used as a provider and/or as a function:
|
|
308
382
|
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
|
|
383
|
+
```ts
|
|
384
|
+
import { Jimpex } from 'jimpex';
|
|
385
|
+
import { myService } from './my-service';
|
|
312
386
|
|
|
313
387
|
class MyApp extends Jimpex {
|
|
314
388
|
boot() {
|
|
315
|
-
...
|
|
316
389
|
this.register(myService);
|
|
317
|
-
|
|
318
|
-
|
|
390
|
+
this.register(
|
|
391
|
+
myService({
|
|
392
|
+
serviceName: 'myService2',
|
|
393
|
+
}),
|
|
394
|
+
);
|
|
319
395
|
}
|
|
320
396
|
}
|
|
321
397
|
```
|
|
322
398
|
|
|
323
|
-
|
|
399
|
+
Check the README of [`@homer0/jimple`](https://www.npmjs.com/package/@homer0/jimple) for more information about providers.
|
|
324
400
|
|
|
325
|
-
|
|
401
|
+
### 🚦 Controllers
|
|
326
402
|
|
|
327
|
-
|
|
328
|
-
|
|
403
|
+
To define a controller, you just need to use the `controller` wrapper (like `provider`), modify a router, and return it:
|
|
404
|
+
|
|
405
|
+
```ts
|
|
406
|
+
// src/health-controller.js
|
|
407
|
+
import { controller } from 'jimpex';
|
|
329
408
|
|
|
330
409
|
// (Optional) Define a class to organize your route handlers.
|
|
331
|
-
class HealthController {
|
|
410
|
+
export class HealthController {
|
|
332
411
|
health() {
|
|
333
412
|
return (req, res) => {
|
|
334
413
|
res.write('Everything works!');
|
|
414
|
+
res.end();
|
|
335
415
|
};
|
|
336
416
|
}
|
|
337
417
|
}
|
|
338
418
|
|
|
339
419
|
// Define the controller
|
|
340
|
-
const healthController = controller((app) => {
|
|
420
|
+
export const healthController = controller((app) => {
|
|
341
421
|
const ctrl = new HealthController();
|
|
342
|
-
// Get the router service
|
|
422
|
+
// Get an instance of the router service
|
|
343
423
|
const router = app.get('router');
|
|
344
424
|
// Return the router with all the routes
|
|
345
|
-
return router
|
|
346
|
-
|
|
347
|
-
|
|
425
|
+
return router.get('/', ctrl.health()).get('/health', (req, res) => {
|
|
426
|
+
res.write('Everything works!');
|
|
427
|
+
res.end();
|
|
428
|
+
});
|
|
348
429
|
});
|
|
349
|
-
|
|
350
|
-
// Export the controller class and the controller itself
|
|
351
|
-
module.exports.HealthController = HealthController;
|
|
352
|
-
module.exports.healthController = healthController;
|
|
353
430
|
```
|
|
354
431
|
|
|
355
|
-
> 1. You could just export the controller, but I believe is a good practice to export both in case another part of your app wants to extend the class and mount a new route
|
|
356
|
-
> 2.
|
|
357
|
-
> 3. The function inside the `controller` wrapper won't be called until the app is started. In case you are wondering about the lazy loading of the services that you may inject.
|
|
432
|
+
> 1. You could just export the controller, but I believe is a good practice to export both, in case another part of your app wants to extend the class and mount a new route with its inherited functionalities.
|
|
433
|
+
> 2. In case you are wondering about the lazy loading of the services that you may inject, the function inside the `controller` wrapper won't be called until the app is started.
|
|
358
434
|
|
|
359
435
|
Then, on you app, you would `mount` the controller:
|
|
360
436
|
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
|
|
437
|
+
```ts
|
|
438
|
+
import { Jimpex } from 'jimpex';
|
|
439
|
+
import { healthController } from './health-controller';
|
|
364
440
|
|
|
365
441
|
class MyApp extends Jimpex {
|
|
366
442
|
boot() {
|
|
367
|
-
...
|
|
368
443
|
this.mount('/health', healthController);
|
|
369
444
|
}
|
|
370
445
|
}
|
|
371
446
|
```
|
|
372
447
|
|
|
373
|
-
|
|
448
|
+
Jimpex already comes with a few built-in controllers ready to be used, and you can read about them on the [controllers document](https://github.com/homer0/jimpex/blob/main/documents/controllers.md).
|
|
374
449
|
|
|
375
|
-
|
|
376
|
-
instantiated, using a _"controller creator"_:
|
|
450
|
+
#### Configurable controllers
|
|
377
451
|
|
|
378
|
-
|
|
379
|
-
const { controllerCreator } = require('jimpex');
|
|
452
|
+
The same as with the services, you can define controllers that accept custom options for the moment they are mounted:
|
|
380
453
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
454
|
+
```ts
|
|
455
|
+
// src/health-controller.js
|
|
456
|
+
import { controllerCreator } from 'jimpex';
|
|
384
457
|
|
|
458
|
+
// (Optional) Define a class to organize your route handlers.
|
|
459
|
+
export class HealthController {
|
|
385
460
|
health() {
|
|
386
461
|
return (req, res) => {
|
|
387
462
|
res.write('Everything works!');
|
|
463
|
+
res.end();
|
|
388
464
|
};
|
|
389
465
|
}
|
|
390
466
|
}
|
|
391
467
|
|
|
392
468
|
// Define the controller
|
|
393
|
-
const healthController = controllerCreator((
|
|
394
|
-
const ctrl = new HealthController(
|
|
395
|
-
// Get the router service
|
|
469
|
+
export const healthController = controllerCreator((options = {}) => (app) => {
|
|
470
|
+
const ctrl = new HealthController();
|
|
471
|
+
// Get an instance of the router service
|
|
396
472
|
const router = app.get('router');
|
|
473
|
+
// Read the custom options
|
|
474
|
+
const { altRoute = '/health' } = options;
|
|
475
|
+
|
|
397
476
|
// Return the router with all the routes
|
|
398
|
-
return router
|
|
399
|
-
|
|
400
|
-
|
|
477
|
+
return router.get('/', ctrl.health()).get(altRoute, (req, res) => {
|
|
478
|
+
res.write('Everything works!');
|
|
479
|
+
res.end();
|
|
480
|
+
});
|
|
401
481
|
});
|
|
402
|
-
|
|
403
|
-
// Export the controller class and the controller itself
|
|
404
|
-
module.exports.HealthController = HealthController;
|
|
405
|
-
module.exports.healthController = healthController;
|
|
406
482
|
```
|
|
407
483
|
|
|
408
|
-
|
|
484
|
+
And like with the provider creators, these can be used as a controller, or as a function:
|
|
409
485
|
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
|
|
486
|
+
```ts
|
|
487
|
+
import { Jimpex } from 'jimpex';
|
|
488
|
+
import { healthController } from './health-controller';
|
|
413
489
|
|
|
414
490
|
class MyApp extends Jimpex {
|
|
415
491
|
boot() {
|
|
416
|
-
...
|
|
417
492
|
this.mount('/health', healthController);
|
|
418
|
-
|
|
419
|
-
|
|
493
|
+
this.mount(
|
|
494
|
+
'/hp',
|
|
495
|
+
healthController({
|
|
496
|
+
altRoute: '/status',
|
|
497
|
+
}),
|
|
498
|
+
);
|
|
420
499
|
}
|
|
421
500
|
}
|
|
422
501
|
```
|
|
423
502
|
|
|
424
|
-
####
|
|
425
|
-
|
|
426
|
-
If for some reason, your controller needs to register a service the rest of the container needs to have access to and you plan to do it on the `controller`/`controllerCreator` callback, you could end up messing with the _lazyness_ of the container: If a middleware or another controller tries to access the service and the controller that registers it is mounter after it, it will get an error as the service doesn't exist yet.
|
|
503
|
+
#### Controllers with services
|
|
427
504
|
|
|
428
|
-
|
|
505
|
+
If for some reason, your controller needs to register a service that the rest of the container needs to have access to, and you plan to do it on the `controller`/`controllerCreator` callback, you could end up messing with the _lazyness_ of the container: If a middleware or another controller tries to access the service and the controller that registers it is mounted after it, it will get an error as the service _doesn't exist yet_.
|
|
429
506
|
|
|
430
|
-
|
|
431
|
-
const { provider, controller } = require('jimpex');
|
|
507
|
+
A way to solve this issue would be with a `provider`/`providerCreator`, mounting the controller:
|
|
432
508
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return (req, res) => {
|
|
437
|
-
res.write('Everything works!');
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
}
|
|
509
|
+
```ts
|
|
510
|
+
// dont-do-this.js
|
|
511
|
+
import { provider, controller } from 'jimpex';
|
|
441
512
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
// Return the router with all the routes
|
|
452
|
-
return router
|
|
453
|
-
.get('/', ctrl.health())
|
|
454
|
-
.get(...);
|
|
455
|
-
});
|
|
513
|
+
export const wrong = provider((app) => {
|
|
514
|
+
app.set('wrong', () => new WrongService());
|
|
515
|
+
app.mount(
|
|
516
|
+
'/',
|
|
517
|
+
controller((app) => {
|
|
518
|
+
const wrong = app.get('wrong');
|
|
519
|
+
return router.get('/', wrong.doSomething());
|
|
520
|
+
}),
|
|
521
|
+
);
|
|
456
522
|
});
|
|
457
|
-
|
|
458
|
-
// Export the controller class and the controller itself
|
|
459
|
-
module.exports.HealthController = HealthController;
|
|
460
|
-
module.exports.healthController = healthController;
|
|
461
523
|
```
|
|
462
524
|
|
|
463
|
-
|
|
525
|
+
The main problem with that approach is that you would have to `register` it as a provider, so the route for the controller would need to be defined inside the callback.
|
|
464
526
|
|
|
465
|
-
|
|
466
|
-
const { Jimpex } = require('jimpex');
|
|
467
|
-
const { healthController } = require('...');
|
|
527
|
+
So, for this case, Jimpex has a special wrapper, which is very similar, but that it allows you to `mount` it:
|
|
468
528
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
this.mount('/health', healthController);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
```
|
|
529
|
+
```ts
|
|
530
|
+
// controller-provider.js
|
|
531
|
+
import { controllerProvider, controller } from 'jimpex';
|
|
476
532
|
|
|
477
|
-
|
|
533
|
+
export const good = controllerProvider((app) => {
|
|
534
|
+
app.set('good', () => new GoodService());
|
|
478
535
|
|
|
479
|
-
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
app.set('health', () => new HealthController(settings));
|
|
483
|
-
return controller(() => {
|
|
484
|
-
// Get the controller as a service
|
|
485
|
-
const ctrl = app.get('health');
|
|
486
|
-
// Get the router service
|
|
487
|
-
const router = app.get('router');
|
|
488
|
-
// Return the router with all the routes
|
|
489
|
-
return router
|
|
490
|
-
.get('/', ctrl.health())
|
|
491
|
-
.get(...);
|
|
536
|
+
return controller((app) => {
|
|
537
|
+
const good = app.get('good');
|
|
538
|
+
return router.get('/', good.doSomething());
|
|
492
539
|
});
|
|
493
540
|
});
|
|
494
541
|
```
|
|
495
542
|
|
|
496
|
-
|
|
543
|
+
The `controllerProvider` wrapper allows you to register something in the callback, and expects a wrapped `controller` to be returned. That way, you can `mount` it, and specify the root outside.
|
|
497
544
|
|
|
498
|
-
|
|
545
|
+
And like `provider`, and `controller`, there's also a `controllerProviderCreator`.
|
|
499
546
|
|
|
500
|
-
|
|
501
|
-
|
|
547
|
+
### ⚡️ Middlewares
|
|
548
|
+
|
|
549
|
+
To create a new middleware, you just need to use the `middleware` wrapper and return it:
|
|
550
|
+
|
|
551
|
+
```ts
|
|
552
|
+
// my-middleware.js
|
|
553
|
+
import { middleware } from 'jimpex';
|
|
502
554
|
|
|
503
555
|
// Define your middleware function (or class if it gets more complex)
|
|
504
|
-
const greetingsMiddleware = () => (req, res, next) => {
|
|
505
|
-
|
|
556
|
+
export const greetingsMiddleware = () => (req, res, next) => {
|
|
557
|
+
try {
|
|
558
|
+
res.write('Hello World!');
|
|
559
|
+
res.end();
|
|
560
|
+
} catch (err) {
|
|
561
|
+
next(err);
|
|
562
|
+
}
|
|
506
563
|
};
|
|
507
564
|
|
|
508
565
|
// Define the middleware
|
|
509
|
-
const greetings = middleware(() => greetingsMiddleware());
|
|
510
|
-
|
|
511
|
-
// Export the function and the middleware
|
|
512
|
-
module.exports.greetingsMiddleware = greetingsMiddleware;
|
|
513
|
-
module.exports.greetings = greetings;
|
|
566
|
+
export const greetings = middleware(() => greetingsMiddleware());
|
|
514
567
|
```
|
|
515
568
|
|
|
516
|
-
|
|
517
|
-
> 2. That why of using `module.expots` is so the function can be imported on JSDoc comments.
|
|
569
|
+
Then, on the app, you would `use` it:
|
|
518
570
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const { Jimpex } = require('jimpex');
|
|
523
|
-
const { greetings } = require('...');
|
|
571
|
+
```ts
|
|
572
|
+
import { Jimpex } from 'jimpex';
|
|
573
|
+
import { greetings } from './my-middleware';
|
|
524
574
|
|
|
525
575
|
class MyApp extends Jimpex {
|
|
526
576
|
boot() {
|
|
527
|
-
...
|
|
528
577
|
this.use(greetings);
|
|
529
578
|
}
|
|
530
579
|
}
|
|
531
580
|
```
|
|
532
581
|
|
|
533
|
-
|
|
582
|
+
Now, middlewares can also be `mount`ed in specific routes:
|
|
534
583
|
|
|
535
|
-
|
|
584
|
+
```ts
|
|
585
|
+
import { Jimpex } from 'jimpex';
|
|
586
|
+
import { greetings } from './my-middleware';
|
|
536
587
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
console.log(message);
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
// Define the middleware
|
|
546
|
-
const greetings = middlewareCreator((message) => greetingsMiddleware(message));
|
|
547
|
-
|
|
548
|
-
// Export the function and the middleware
|
|
549
|
-
module.exports.greetingsMiddleware = greetingsMiddleware;
|
|
550
|
-
module.exports.greetings = greetings;
|
|
588
|
+
class MyApp extends Jimpex {
|
|
589
|
+
boot() {
|
|
590
|
+
this.mount('/greetings', greetings);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
551
593
|
```
|
|
552
594
|
|
|
553
|
-
|
|
595
|
+
And, if you don't need access to the container in the middleware definition, you could also `mount`/`use` it as a _raw_ Express' middleware:
|
|
554
596
|
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
|
|
597
|
+
```ts
|
|
598
|
+
import { Jimpex } from 'jimpex';
|
|
599
|
+
|
|
600
|
+
const greetingsMiddleware = (req, res, next) => {
|
|
601
|
+
try {
|
|
602
|
+
res.write('Hello World!');
|
|
603
|
+
res.end();
|
|
604
|
+
} catch (err) {
|
|
605
|
+
next(err);
|
|
606
|
+
}
|
|
607
|
+
};
|
|
558
608
|
|
|
559
609
|
class MyApp extends Jimpex {
|
|
560
610
|
boot() {
|
|
561
|
-
|
|
562
|
-
this.use(greetings);
|
|
611
|
+
this.use(greetingsMiddleware);
|
|
563
612
|
// or
|
|
564
|
-
this.
|
|
613
|
+
this.mount('/greetings', greetingsMiddleware);
|
|
565
614
|
}
|
|
566
615
|
}
|
|
567
616
|
```
|
|
568
617
|
|
|
569
|
-
|
|
618
|
+
Jimpex already comes with a few built-in middlewares ready to be used, and you can read about them on the [middlewares document](https://github.com/homer0/jimpex/blob/main/documents/middlewares.md).
|
|
570
619
|
|
|
571
|
-
|
|
620
|
+
#### Configurable middlewares
|
|
572
621
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
622
|
+
Just like the `controllerCreator` wrapper, you can also use the `middlewareCreator` wrapper to define middlewares that accept custom options:
|
|
623
|
+
|
|
624
|
+
```ts
|
|
625
|
+
// my-middleware.js
|
|
626
|
+
import { middlwareCreator } from 'jimpex';
|
|
627
|
+
|
|
628
|
+
// Define your middleware function (or class if it gets more complex)
|
|
629
|
+
export const greetingsMiddleware = (message) => (req, res, next) => {
|
|
630
|
+
try {
|
|
631
|
+
res.write(message);
|
|
632
|
+
res.end();
|
|
633
|
+
} catch (err) {
|
|
634
|
+
next(err);
|
|
586
635
|
}
|
|
587
|
-
}
|
|
588
|
-
// Define the provider
|
|
589
|
-
const greetings = provider((app) => {
|
|
590
|
-
// Register the class as a service
|
|
591
|
-
app.set('greeter', () => new Greeter());
|
|
592
|
-
// Return the actual middleware
|
|
593
|
-
return middleware(() => app.get('greeter').middleware());
|
|
594
|
-
})
|
|
636
|
+
};
|
|
595
637
|
|
|
596
|
-
//
|
|
597
|
-
|
|
598
|
-
|
|
638
|
+
// Define the middleware
|
|
639
|
+
export const greetings = middleware((options) => {
|
|
640
|
+
const { message = 'Hello Charo!' } = options;
|
|
641
|
+
return greetingsMiddleware(message);
|
|
642
|
+
});
|
|
599
643
|
```
|
|
600
644
|
|
|
601
|
-
And you
|
|
645
|
+
And now you can use it as a middleware, or as a function that returns a middleware:
|
|
602
646
|
|
|
603
|
-
```
|
|
604
|
-
|
|
605
|
-
|
|
647
|
+
```ts
|
|
648
|
+
import { Jimpex } from 'jimpex';
|
|
649
|
+
import { greetings } from './my-middleware';
|
|
606
650
|
|
|
607
651
|
class MyApp extends Jimpex {
|
|
608
652
|
boot() {
|
|
609
|
-
...
|
|
610
653
|
this.use(greetings);
|
|
654
|
+
// or
|
|
655
|
+
this.mount(
|
|
656
|
+
'/greetings',
|
|
657
|
+
greetings({
|
|
658
|
+
message: 'Hello Pili!',
|
|
659
|
+
}),
|
|
660
|
+
);
|
|
611
661
|
}
|
|
612
662
|
}
|
|
613
663
|
```
|
|
614
664
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
```js
|
|
618
|
-
const greetings = providerCreator((settings) => (app) => {
|
|
619
|
-
// Register the class as a service and send the settings
|
|
620
|
-
app.set('greeter', () => new Greeter(settings));
|
|
621
|
-
// Return the actual middleware
|
|
622
|
-
return middleware(() => app.get('greeter').middleware());
|
|
623
|
-
});
|
|
624
|
-
```
|
|
625
|
-
|
|
626
|
-
### Proxy mode
|
|
627
|
-
|
|
628
|
-
You can enable the "proxy mode" by setting the `proxy` option to `true` on either the function or the class and it allows you to access and register resources using dot notation:
|
|
629
|
-
|
|
630
|
-
```js
|
|
631
|
-
// Set the option
|
|
632
|
-
const app = jimpex({ proxy: true });
|
|
665
|
+
#### Middlewares with services
|
|
633
666
|
|
|
634
|
-
|
|
635
|
-
// = app.set('myService', () => new MyService();
|
|
667
|
+
If, for some reason, your middleware needs to register a service before being mounted, just like the `controllerProvider`, you have the `middlewareProvider` wrapper:
|
|
636
668
|
|
|
637
|
-
|
|
638
|
-
//
|
|
669
|
+
```ts
|
|
670
|
+
// middleware-provider.js
|
|
671
|
+
import { middlewareProvider, middleware } from 'jimpex';
|
|
639
672
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
673
|
+
class MiddlewareService {
|
|
674
|
+
getMiddleware() {
|
|
675
|
+
return (req, res) => {
|
|
676
|
+
res.write('Everything works!');
|
|
677
|
+
res.end();
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
}
|
|
643
681
|
|
|
644
|
-
|
|
682
|
+
export const middlewareService = middlewareProvider((app) => {
|
|
683
|
+
app.set('middlewareService', () => new MiddlewareService());
|
|
645
684
|
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
|
|
685
|
+
return middleware((app) => {
|
|
686
|
+
const service = app.get('middlewareService');
|
|
687
|
+
return service.getMiddleware();
|
|
688
|
+
});
|
|
689
|
+
});
|
|
649
690
|
```
|
|
650
691
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
Internally, when `proxy` is enabled, all providers, controllers and middlewares will receive the proxy instead of the original.
|
|
654
|
-
|
|
655
|
-
## Built-in features
|
|
656
|
-
|
|
657
|
-
Jimpex comes with a few services, middlewares and controllers that you can import and use on your app, some of them [are activated by default on the options](./documents/options.md), but others you have to implement manually:
|
|
692
|
+
And finally, you also have `middlewareProviderCreator` to create a middleware that can register a service, with custom options.
|
|
658
693
|
|
|
659
|
-
|
|
694
|
+
## 💪 TypeScript
|
|
660
695
|
|
|
661
|
-
|
|
662
|
-
- **Health:** Shows the version and name of the configuration, just to check the app is running.
|
|
663
|
-
- **Statics:** It allows your app to server specific files from any directory, without having to use the `static` middleware.
|
|
664
|
-
- **Gateway:** It allows you to automatically generate a set of routes that will make gateway requests to an specific API.
|
|
696
|
+
After v8, Jimpex was completely rewritten in TypeScript, so you can use it with no problems in your TypeScript projects. For more information, please refer to the [TypeScript document](https://github.com/homer0/jimpex/blob/main/documents/typescript.md).
|
|
665
697
|
|
|
666
|
-
|
|
698
|
+
## 🤞 Examples
|
|
667
699
|
|
|
668
|
-
|
|
700
|
+
You can find the example projects in the `example` directory. To run them, you can use the `npm run example` command. By default, it runs the `basic` example, but you can also specify the name of the example you want to run:
|
|
669
701
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
- **Fast HTML:** Allows your app to skip unnecessary processing by showing an specific HTML when a requested route doesn't have a controller for it or is not on a "whitelist".
|
|
674
|
-
- **Show HTML:** A really simple middleware to serve an HTML file. Its true feature is that it can be hooked up to the **HTML Generator** service.
|
|
675
|
-
- **Version validator:** If you mount it on a route it will generate a `409` error if the request doesn't have a version parameter with the same version as the one on the configuration.
|
|
676
|
-
|
|
677
|
-
[Read more about the built-in controllers](./documents/middlewares.md)
|
|
678
|
-
|
|
679
|
-
### Services
|
|
680
|
-
|
|
681
|
-
- **API client:** An implementation of the [wootils API Client](https://github.com/homer0/wootils/blob/main/documents/shared/APIClient.md) but that is connected to the HTTP service, to allow logging and forwarding of the headers.
|
|
682
|
-
- **App Error:** A very simple subclass of `Error` but with support for context information. It can be used to customize the error handler responses.
|
|
683
|
-
- **Ensure bearer token:** A service-middleware that allows you to validate and retrieve a bearer token from the incoming requests `Authorization` header.
|
|
684
|
-
- **HTTP Error:** Another type of error, but specific for the HTTP requests the app does with the API client.
|
|
685
|
-
- **Send File:** It allows you to send a file on a response with a path relative to the app executable.
|
|
686
|
-
- **Frontend Fs:** Useful for when your app has a bundled frontend, it allows you to read, write and delete files with paths relative to the app executable.
|
|
687
|
-
- **HTML Generator:** A service that allows you to generate an HTML file when the app gets started and inject contents of the configuration as a `window` variable.
|
|
688
|
-
- **HTTP:** A set of utilities to work with HTTP requests and responses.
|
|
689
|
-
- **Responses builder:** A service that generates JSON and HTML responses.
|
|
690
|
-
|
|
691
|
-
[Read more about the built-in services](./documents/services.md)
|
|
692
|
-
|
|
693
|
-
The service also implements a few other services from the [wootils](https://github.com/homer0/wootils) as core utilities:
|
|
694
|
-
|
|
695
|
-
- [`appLogger`](https://github.com/homer0/wootils/blob/main/documents/node/logger.md): The logger service.
|
|
696
|
-
- [`environmentUtils`](https://github.com/homer0/wootils/blob/main/documents/node/environmentUtils.md): The service that reads the environment variables.
|
|
697
|
-
- [`packageInfo`](https://github.com/homer0/wootils/blob/main/documents/node/packageInfo.md): The app package.json information.
|
|
698
|
-
- [`pathUtils`](https://github.com/homer0/wootils/blob/main/documents/node/pathUtils.md): The service to build paths relative to the project root directory.
|
|
699
|
-
- [`rootRequire`](https://github.com/homer0/wootils/blob/main/documents/node/rootRequire.md): The service to make requires relatives to the project root directory.
|
|
700
|
-
- [`events`](https://github.com/homer0/wootils/blob/main/documents/shared/eventsHub.md): To handle the app events.
|
|
702
|
+
```bash
|
|
703
|
+
npm run example [name-of-the-directory]
|
|
704
|
+
```
|
|
701
705
|
|
|
702
|
-
## Development
|
|
706
|
+
## 🤘 Development
|
|
703
707
|
|
|
704
|
-
### NPM
|
|
708
|
+
### NPM scripts
|
|
705
709
|
|
|
706
|
-
|
|
|
707
|
-
|
|
708
|
-
| `
|
|
709
|
-
| `
|
|
710
|
-
| `lint
|
|
711
|
-
| `
|
|
712
|
-
| `
|
|
710
|
+
| Script | Description |
|
|
711
|
+
| ------------- | ------------------------------------ |
|
|
712
|
+
| `build` | Transpiles the TypeScript code. |
|
|
713
|
+
| `docs` | Generates the project documentation. |
|
|
714
|
+
| `lint` | Lints and formats the staged files. |
|
|
715
|
+
| `lint:all` | Lints the entire project code. |
|
|
716
|
+
| `types:check` | Validates the types definitions. |
|
|
717
|
+
| `test` | Runs the project unit tests. |
|
|
718
|
+
| `todo` | Lists all the pending to-do's. |
|
|
719
|
+
| `example` | Runs an example project. |
|
|
713
720
|
|
|
714
721
|
### Repository hooks
|
|
715
722
|
|
|
716
|
-
I use [`husky`](https://
|
|
723
|
+
I use [`husky`](https://npmjs.com/package/husky) to automatically install the repository hooks:
|
|
724
|
+
|
|
725
|
+
| Hook | Description |
|
|
726
|
+
| ------------ | ---------------------------------------- |
|
|
727
|
+
| `commit-msg` | Ensures the use of conventional commits. |
|
|
728
|
+
| `pre-commit` | Lints and formats the staged files. |
|
|
729
|
+
| `pre-push` | Validates the types and run the tests. |
|
|
730
|
+
| `post-merge` | Updates the dependencies (`npm i`). |
|
|
717
731
|
|
|
718
|
-
|
|
732
|
+
### Commits conventions
|
|
719
733
|
|
|
720
|
-
I use [conventional commits](https://www.conventionalcommits.org) with [`commitlint`](https://commitlint.js.org) in order to support semantic releases. The one that sets it up is actually husky
|
|
734
|
+
I use [conventional commits](https://www.conventionalcommits.org) with [`commitlint`](https://commitlint.js.org) in order to support semantic releases. The one that sets it up is actually `husky`, since it installs a script that runs `commitlint` on the commit message validation.
|
|
721
735
|
|
|
722
736
|
The configuration is on the `commitlint` property of the `package.json`.
|
|
723
737
|
|
|
724
738
|
### Releases
|
|
725
739
|
|
|
726
|
-
I use [`semantic-release`](https://
|
|
740
|
+
I use [`semantic-release`](https://npmjs.com/package/semantic-release) and a GitHub action to automatically release on NPM everything that gets merged to main.
|
|
727
741
|
|
|
728
742
|
The configuration for `semantic-release` is on `./releaserc` and the workflow for the release is on `./.github/workflow/release.yml`.
|
|
729
743
|
|
|
730
744
|
### Testing
|
|
731
745
|
|
|
732
|
-
I use [Jest](https://
|
|
746
|
+
I use [Jest](https://jestjs.io) to test the project.
|
|
733
747
|
|
|
734
748
|
The configuration file is on `./.jestrc.js`, the tests are on `./tests` and the script that runs it is on `./utils/scripts/test`.
|
|
735
749
|
|
|
736
750
|
### Code linting and formatting
|
|
737
751
|
|
|
738
|
-
For linting, I use [ESlint](https://eslint.org) with [my own custom configuration](https://
|
|
752
|
+
For linting, I use [ESlint](https://eslint.org) with [my own custom configuration](https://npmjs.com/package/@homer0/eslint-plugin).
|
|
753
|
+
|
|
754
|
+
There are two configuration files, `./.eslintrc` for the source and the tooling, and `./tests/.eslintrc`, and there's also a `./.eslintignore` to exclude some files.
|
|
739
755
|
|
|
740
|
-
|
|
756
|
+
For formatting, I use [Prettier](https://prettier.io) with [my JSDoc plugin](https://npmjs.com/package/@homer0/prettier-plugin-jsdoc) and [my own custom configuration](https://npmjs.com/package/@homer0/prettier-config). The configuration file is `./.prettierrc`.
|
|
741
757
|
|
|
742
758
|
The script that runs them is `./utils/scripts/lint`; the script `lint-all` only runs ESLint, and runs it for the entire project.
|
|
743
759
|
|
|
744
760
|
### Documentation
|
|
745
761
|
|
|
746
|
-
I use [
|
|
747
|
-
|
|
748
|
-
The configuration file is `./.jsdoc.js` and the script that runs it is on `./utils/scripts/docs`.
|
|
749
|
-
|
|
750
|
-
### To-Dos
|
|
762
|
+
I use [TypeDoc](https://typedoc.org) to generate an HTML documentation site for the project.
|
|
751
763
|
|
|
752
|
-
|
|
764
|
+
The configuration file is `./.typedoc.json` and the script that runs it is on `./utils/scripts/docs`.
|
|
753
765
|
|
|
754
|
-
## Motivation
|
|
766
|
+
## 👀 Motivation
|
|
755
767
|
|
|
756
|
-
A friend who's also web developer brought the idea of start using a dependency injection container on Node, and how Jimple was a great tool for it
|
|
768
|
+
A friend, who's also web developer, brought the idea of start using a dependency injection container on Node, and how Jimple was a great tool for it; from the moment I tried Jimple, I could never think of starting another project without it: It not only allows you to implement dependency injection on a simple and clean way, but it also kind of forces you to have a really good organization of your code.
|
|
757
769
|
|
|
758
|
-
A couple of months after that, the same friend told me that we should do something similar to [Silex](https://
|
|
770
|
+
A couple of months after that, the same friend told me that we should do something similar to [Silex](https://github.com/silexphp/Silex), which is based on Pimple, butwith Express. I ran with the idea and... this project is what I think a mix of Jimple and Express would look like. To be clear, **this is not a port of Silex**.
|