jimpex 7.0.2 → 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 +80 -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
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The name of all the events {@link Jimpex} can trigger.
|
|
3
|
-
*
|
|
4
|
-
* @typedef {Object} JimpexEvents
|
|
5
|
-
* @property {string} beforeStop Called before closing the instance of the
|
|
6
|
-
* app.
|
|
7
|
-
* @property {string} start Called from the `listen` callback, when the
|
|
8
|
-
* app is ready to be used.
|
|
9
|
-
* @property {string} afterStart Called from the `listen` callback, when all
|
|
10
|
-
* controllers and middlewares have been
|
|
11
|
-
* mounted.
|
|
12
|
-
* @property {string} afterStartCallback Called right after the callback sent to
|
|
13
|
-
* `start`
|
|
14
|
-
* gets executed.
|
|
15
|
-
* @property {string} beforeStart Called before `listen` is executed on the
|
|
16
|
-
* Express app.
|
|
17
|
-
* @property {string} afterStop Called after the app instance has been
|
|
18
|
-
* closed and deleted.
|
|
19
|
-
* @property {string} routeAdded Called every time a new route is added to
|
|
20
|
-
* the app.
|
|
21
|
-
* @property {string} controllerWillBeMounted This is for a reducer event. It gets called
|
|
22
|
-
* before mounting a router or a set of routes
|
|
23
|
-
* to the app in order to "reduce it".
|
|
24
|
-
* @property {string} middlewareWillBeUsed This is for a reducer event. It gets called
|
|
25
|
-
* before using a middleware in order to
|
|
26
|
-
* "reduce it".
|
|
27
|
-
* @parent module:constants
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The name of all the events {@link Jimpex} can trigger.
|
|
32
|
-
*
|
|
33
|
-
* @type {JimpexEvents}
|
|
34
|
-
* @parent module:constants
|
|
35
|
-
*/
|
|
36
|
-
const eventNames = {
|
|
37
|
-
beforeStart: 'before-start',
|
|
38
|
-
start: 'start',
|
|
39
|
-
afterStart: 'after-start',
|
|
40
|
-
afterStartCallback: 'after-start-callback',
|
|
41
|
-
beforeStop: 'before-stop',
|
|
42
|
-
afterStop: 'after-stop',
|
|
43
|
-
controllerWillBeMounted: 'controller-will-be-mounted',
|
|
44
|
-
routeAdded: 'route-added',
|
|
45
|
-
middlewareWillBeUsed: 'middleware-will-be-used',
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
module.exports = eventNames;
|
package/src/constants/index.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
const { controller } = require('../../utils/wrappers');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {import('../../types').ExpressMiddleware} ExpressMiddleware
|
|
5
|
-
* @typedef {import('../../types').ExpressResponse} ExpressResponse
|
|
6
|
-
* @typedef {import('../../types').AppConfiguration} AppConfiguration
|
|
7
|
-
* @typedef {import('../../services/http/responsesBuilder').ResponsesBuilder} ResponsesBuilder
|
|
8
|
-
* @typedef {import('../../types').Controller} Controller
|
|
9
|
-
* @prettierignore
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Provides the handlers and middlwares to show and switch configurations.
|
|
14
|
-
*
|
|
15
|
-
* @parent module:controllers
|
|
16
|
-
*/
|
|
17
|
-
class ConfigurationController {
|
|
18
|
-
/**
|
|
19
|
-
* @param {AppConfiguration} appConfiguration To read the app configuration.
|
|
20
|
-
* @param {ResponsesBuilder} responsesBuilder To generate the JSON responses.
|
|
21
|
-
*/
|
|
22
|
-
constructor(appConfiguration, responsesBuilder) {
|
|
23
|
-
/**
|
|
24
|
-
* A local reference for the `appConfiguration` service.
|
|
25
|
-
*
|
|
26
|
-
* @type {AppConfiguration}
|
|
27
|
-
* @access protected
|
|
28
|
-
* @ignore
|
|
29
|
-
*/
|
|
30
|
-
this._appConfiguration = appConfiguration;
|
|
31
|
-
/**
|
|
32
|
-
* A local reference for the `responsesBuilder` service.
|
|
33
|
-
*
|
|
34
|
-
* @type {ResponsesBuilder}
|
|
35
|
-
* @access protected
|
|
36
|
-
* @ignore
|
|
37
|
-
*/
|
|
38
|
-
this._responsesBuilder = responsesBuilder;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Send a response with the current app configuration as a body.
|
|
42
|
-
*
|
|
43
|
-
* @param {ExpressResponse} res The server response.
|
|
44
|
-
*/
|
|
45
|
-
getConfigurationResponse(res) {
|
|
46
|
-
const name = this._appConfiguration.get('name');
|
|
47
|
-
const data = {
|
|
48
|
-
name,
|
|
49
|
-
...this._appConfiguration.getConfig(),
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
this._responsesBuilder.json(res, data);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Returns the middleware to show the current configuration.
|
|
56
|
-
*
|
|
57
|
-
* @returns {ExpressMiddleware}
|
|
58
|
-
*/
|
|
59
|
-
showConfiguration() {
|
|
60
|
-
return (req, res) => {
|
|
61
|
-
this.getConfigurationResponse(res);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns the middleware to switch the current configuration.
|
|
66
|
-
*
|
|
67
|
-
* @returns {ExpressMiddleware}
|
|
68
|
-
*/
|
|
69
|
-
switchConfiguration() {
|
|
70
|
-
return (req, res, next) => {
|
|
71
|
-
if (this._appConfiguration.canSwitch()) {
|
|
72
|
-
try {
|
|
73
|
-
this._appConfiguration.switch(req.params.name);
|
|
74
|
-
this.getConfigurationResponse(res);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
next(error);
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
next();
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* This controller is kind of special as it will only mount the routes if the
|
|
86
|
-
* `debug.configurationController` setting of the app configuration is `true`.
|
|
87
|
-
* It provides routes for:
|
|
88
|
-
* - Showing the current configuration.
|
|
89
|
-
* - Switching the configuration, but only if the service allows it.
|
|
90
|
-
*
|
|
91
|
-
* @type {Controller}
|
|
92
|
-
* @parent module:controllers
|
|
93
|
-
* @todo Don't use an array to return the routes.
|
|
94
|
-
*/
|
|
95
|
-
const configurationController = controller((app) => {
|
|
96
|
-
const routes = [];
|
|
97
|
-
const appConfiguration = app.get('appConfiguration');
|
|
98
|
-
if (appConfiguration.get('debug.configurationController') === true) {
|
|
99
|
-
const router = app.get('router');
|
|
100
|
-
const ctrl = new ConfigurationController(
|
|
101
|
-
appConfiguration,
|
|
102
|
-
app.get('responsesBuilder'),
|
|
103
|
-
);
|
|
104
|
-
routes.push(
|
|
105
|
-
...[
|
|
106
|
-
router.get('/', ctrl.showConfiguration()),
|
|
107
|
-
router.get('/switch/:name', ctrl.switchConfiguration()),
|
|
108
|
-
],
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return routes;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
module.exports.ConfigurationController = ConfigurationController;
|
|
116
|
-
module.exports.configurationController = configurationController;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const { code: statuses } = require('statuses');
|
|
2
|
-
const { controller } = require('../../utils/wrappers');
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {import('../../types').ExpressMiddleware} ExpressMiddleware
|
|
5
|
-
* @typedef {import('../../types').AppConfiguration} AppConfiguration
|
|
6
|
-
* @typedef {import('../../types').Controller} Controller
|
|
7
|
-
* @typedef {import('../../services/http/responsesBuilder').ResponsesBuilder} ResponsesBuilder
|
|
8
|
-
* @prettierignore
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Provides the handler to show a some minimal health information about the app:
|
|
13
|
-
* - app version.
|
|
14
|
-
* - configuration name.
|
|
15
|
-
*
|
|
16
|
-
* @parent module:controllers
|
|
17
|
-
*/
|
|
18
|
-
class HealthController {
|
|
19
|
-
/**
|
|
20
|
-
* @param {AppConfiguration} appConfiguration To read the app version and the
|
|
21
|
-
* configuration name.
|
|
22
|
-
* @param {ResponsesBuilder} responsesBuilder To generate the JSON response.
|
|
23
|
-
*/
|
|
24
|
-
constructor(appConfiguration, responsesBuilder) {
|
|
25
|
-
/**
|
|
26
|
-
* A local reference for the `appConfiguration` service.
|
|
27
|
-
*
|
|
28
|
-
* @type {AppConfiguration}
|
|
29
|
-
* @access protected
|
|
30
|
-
* @ignore
|
|
31
|
-
*/
|
|
32
|
-
this._appConfiguration = appConfiguration;
|
|
33
|
-
/**
|
|
34
|
-
* A local reference for the `responsesBuilder` service.
|
|
35
|
-
*
|
|
36
|
-
* @type {ResponsesBuilder}
|
|
37
|
-
* @access protected
|
|
38
|
-
* @ignore
|
|
39
|
-
*/
|
|
40
|
-
this._responsesBuilder = responsesBuilder;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns the middleware that shows the health information.
|
|
44
|
-
*
|
|
45
|
-
* @returns {ExpressMiddleware}
|
|
46
|
-
*/
|
|
47
|
-
health() {
|
|
48
|
-
return (req, res) => {
|
|
49
|
-
const { name: configuration, version } = this._appConfiguration.get([
|
|
50
|
-
'name',
|
|
51
|
-
'version',
|
|
52
|
-
]);
|
|
53
|
-
this._responsesBuilder.json(res, {
|
|
54
|
-
isHealthy: true,
|
|
55
|
-
status: statuses.ok,
|
|
56
|
-
configuration,
|
|
57
|
-
version,
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Mounts the health route.
|
|
64
|
-
*
|
|
65
|
-
* @type {Controller}
|
|
66
|
-
* @parent module:controllers
|
|
67
|
-
*/
|
|
68
|
-
const healthController = controller((app) => {
|
|
69
|
-
const router = app.get('router');
|
|
70
|
-
const ctrl = new HealthController(
|
|
71
|
-
app.get('appConfiguration'),
|
|
72
|
-
app.get('responsesBuilder'),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return [router.get('/', ctrl.health())];
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
module.exports.HealthController = HealthController;
|
|
79
|
-
module.exports.healthController = healthController;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const { configurationController } = require('./configuration');
|
|
2
|
-
const { healthController } = require('./health');
|
|
3
|
-
const { staticsController } = require('./statics');
|
|
4
|
-
|
|
5
|
-
module.exports.configurationController = configurationController;
|
|
6
|
-
module.exports.healthController = healthController;
|
|
7
|
-
module.exports.staticsController = staticsController;
|
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const ObjectUtils = require('wootils/shared/objectUtils');
|
|
3
|
-
const mime = require('mime');
|
|
4
|
-
const { controllerCreator } = require('../../utils/wrappers');
|
|
5
|
-
const { removeSlashes } = require('../../utils/functions');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {import('../../app').Jimpex} Jimpex
|
|
9
|
-
* @typedef {import('../../types').ExpressMiddleware} ExpressMiddleware
|
|
10
|
-
* @typedef {import('../../types').ExpressRouter} ExpressRouter
|
|
11
|
-
* @typedef {import('../../types').Controller} Controller
|
|
12
|
-
* @typedef {import('../../types').MiddlewareLike} MiddlewareLike
|
|
13
|
-
* @typedef {import('../../services/common/sendFile').SendFile} SendFile
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {import('../../types').ControllerCreator<O>} ControllerCreator<O>
|
|
18
|
-
* @template O
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* If you wan to customize how, to, and from where files are served, instead of just
|
|
23
|
-
* sending a list of strings, you can use an object with these properties.
|
|
24
|
-
*
|
|
25
|
-
* @typedef {Object} StaticsControllerFile
|
|
26
|
-
* @property {string} route The route the controller will use for the
|
|
27
|
-
* file.
|
|
28
|
-
* @property {string} path The path for the file, relative to the
|
|
29
|
-
* root of the app.
|
|
30
|
-
* @property {Object.<string, string>} headers A dictionary of custom headers to send on
|
|
31
|
-
* the file response.
|
|
32
|
-
* @parent module:controllers
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* They are like "master paths" that get prepended to all the file paths and routes the
|
|
37
|
-
* controller use.
|
|
38
|
-
*
|
|
39
|
-
* @typedef {Object} StaticsControllerPathsOptions
|
|
40
|
-
* @property {string} route A custom route to prefix all the file routes.
|
|
41
|
-
* @property {string} source A custom path to prefix all the file paths.
|
|
42
|
-
* @parent module:controllers
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @typedef {string | StaticsControllerFile} StaticsControllerFileLike
|
|
47
|
-
* @parent module:controllers
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* These are the options that allow you to customize the controller, how, to and from
|
|
52
|
-
* where the files are served.
|
|
53
|
-
*
|
|
54
|
-
* @typedef {Object} StaticsControllerOptions
|
|
55
|
-
* @property {StaticsControllerFileLike[]} files A list of filenames or
|
|
56
|
-
* {@link StaticsControllerFile}
|
|
57
|
-
* definitions.
|
|
58
|
-
* @property {Object.<string, boolean>} methods A dictionary of all the HTTP methods
|
|
59
|
-
* the controller will use in order to
|
|
60
|
-
* serve the files. If `all` is set to
|
|
61
|
-
* true, all the other flags will be
|
|
62
|
-
* ignored.
|
|
63
|
-
* @property {StaticsControllerPathsOptions} paths The "master paths" the controller
|
|
64
|
-
* uses to prefix all file routes and
|
|
65
|
-
* paths.
|
|
66
|
-
* @parent module:controllers
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @typedef {StaticsControllerOptions & StaticsControllerWrapperOptionsProperties} StaticsControllerWrapperOptions
|
|
71
|
-
* @parent module:controllers
|
|
72
|
-
* @prettierignore
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @typedef {Object} StaticsControllerWrapperOptionsProperties
|
|
77
|
-
* @property {StaticsControllerMiddlewaresFn} middlewares
|
|
78
|
-
* Function can be used to add custom middlewares on the file routes. If implemented, it
|
|
79
|
-
* must return a list of middlewares when executed.
|
|
80
|
-
* @parent module:controllers
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @callback StaticsControllerMiddlewaresFn
|
|
85
|
-
* @param {Jimpex} app A reference for the container.
|
|
86
|
-
* @returns {MiddlewareLike[]}
|
|
87
|
-
* @parent module:controllers
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* This controller allows you to serve specific files from any folder to any route without
|
|
92
|
-
* the need of mounting directories as "static".
|
|
93
|
-
*
|
|
94
|
-
* @parent module:controllers
|
|
95
|
-
*/
|
|
96
|
-
class StaticsController {
|
|
97
|
-
/**
|
|
98
|
-
* @param {SendFile} sendFile
|
|
99
|
-
* To send the responses for the files.
|
|
100
|
-
* @param {Partial<StaticsControllerOptions>} options
|
|
101
|
-
* The options to customize the controller.
|
|
102
|
-
*/
|
|
103
|
-
constructor(sendFile, options = {}) {
|
|
104
|
-
/**
|
|
105
|
-
* A local reference for the `sendFile` service.
|
|
106
|
-
*
|
|
107
|
-
* @type {SendFile}
|
|
108
|
-
* @access protected
|
|
109
|
-
* @ignore
|
|
110
|
-
*/
|
|
111
|
-
this._sendFile = sendFile;
|
|
112
|
-
/**
|
|
113
|
-
* The controller configuration options.
|
|
114
|
-
*
|
|
115
|
-
* @type {StaticsControllerOptions}
|
|
116
|
-
* @access protected
|
|
117
|
-
* @ignore
|
|
118
|
-
*/
|
|
119
|
-
this._options = this._normalizeOptions(
|
|
120
|
-
ObjectUtils.merge(
|
|
121
|
-
{
|
|
122
|
-
files: options.files || ['favicon.ico', 'index.html'],
|
|
123
|
-
methods: {
|
|
124
|
-
all: false,
|
|
125
|
-
get: true,
|
|
126
|
-
},
|
|
127
|
-
paths: {
|
|
128
|
-
route: '',
|
|
129
|
-
source: './',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
options,
|
|
133
|
-
),
|
|
134
|
-
);
|
|
135
|
-
/**
|
|
136
|
-
* A dictionary of all the formatted files ({@link StaticsControllerFile}). It uses
|
|
137
|
-
* the files routes as keys.
|
|
138
|
-
*
|
|
139
|
-
* @type {Object.<string, StaticsControllerFile>}
|
|
140
|
-
* @access protected
|
|
141
|
-
* @ignore
|
|
142
|
-
*/
|
|
143
|
-
this._files = this._createFiles();
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Defines all the needed routes to serve the files.
|
|
147
|
-
*
|
|
148
|
-
* @param {ExpressRouter} router To generate the routes.
|
|
149
|
-
* @param {ExpressMiddleware[]} [middlewares=[]] A list of custom middlewares that will
|
|
150
|
-
* be added before the one that serves a
|
|
151
|
-
* file.
|
|
152
|
-
* @returns {ExpressRouter}
|
|
153
|
-
*/
|
|
154
|
-
addRoutes(router, middlewares = []) {
|
|
155
|
-
const { methods } = this._options;
|
|
156
|
-
const use = methods.all
|
|
157
|
-
? ['all']
|
|
158
|
-
: Object.keys(methods).reduce(
|
|
159
|
-
(acc, name) => (methods[name] ? [...acc, name] : acc),
|
|
160
|
-
[],
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
Object.keys(this._files).forEach((route) => {
|
|
164
|
-
const file = this._files[route];
|
|
165
|
-
const fileMiddleware = this._getMiddleware(file);
|
|
166
|
-
use.forEach((method) =>
|
|
167
|
-
this._addRoute(router, method, file, fileMiddleware, middlewares),
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
return router;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* The controller configuration options.
|
|
175
|
-
*
|
|
176
|
-
* @type {StaticsControllerOptions}
|
|
177
|
-
* @todo Remove Object.freeze.
|
|
178
|
-
*/
|
|
179
|
-
get options() {
|
|
180
|
-
return Object.freeze(this._options);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Generates a route for an specific file.
|
|
184
|
-
*
|
|
185
|
-
* @param {ExpressRouter} router To create the actual route.
|
|
186
|
-
* @param {string} method The HTTP method for the route.
|
|
187
|
-
* @param {StaticsControllerFile} file The file information.
|
|
188
|
-
* @param {ExpressMiddleware} fileMiddleware The middleware that serves the file.
|
|
189
|
-
* @param {ExpressMiddleware[]} middlewares A list of custom middlewares to add
|
|
190
|
-
* before the one that serves the file.
|
|
191
|
-
* @returns {ExpressRouter}
|
|
192
|
-
* @access protected
|
|
193
|
-
* @ignore
|
|
194
|
-
*/
|
|
195
|
-
_addRoute(router, method, file, fileMiddleware, middlewares) {
|
|
196
|
-
return router[method](file.route, [...middlewares, fileMiddleware]);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Parses each of the received files in order to create a {@link StaticsControllerFile}.
|
|
200
|
-
*
|
|
201
|
-
* @returns {Object.<string, StaticsControllerFile>}
|
|
202
|
-
* @access protected
|
|
203
|
-
* @ignore
|
|
204
|
-
*/
|
|
205
|
-
_createFiles() {
|
|
206
|
-
const { files, paths } = this._options;
|
|
207
|
-
const routePath = removeSlashes(paths.route, false, true);
|
|
208
|
-
return files.reduce((formatted, file) => {
|
|
209
|
-
let source;
|
|
210
|
-
let route;
|
|
211
|
-
let headers;
|
|
212
|
-
if (typeof file === 'object') {
|
|
213
|
-
({ route, source, headers } = file);
|
|
214
|
-
} else {
|
|
215
|
-
source = file;
|
|
216
|
-
route = file;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
source = path.join(paths.source, source);
|
|
220
|
-
route = removeSlashes(route, true, false);
|
|
221
|
-
route = `${routePath}/${route}`;
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
...formatted,
|
|
225
|
-
[route]: {
|
|
226
|
-
source,
|
|
227
|
-
route,
|
|
228
|
-
headers: headers || {},
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
}, {});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Generates the middleware to serve a specific file.
|
|
235
|
-
*
|
|
236
|
-
* @param {StaticsControllerFile} file The file information.
|
|
237
|
-
* @returns {ExpressMiddleware}
|
|
238
|
-
* @access protected
|
|
239
|
-
* @ignore
|
|
240
|
-
*/
|
|
241
|
-
_getMiddleware(file) {
|
|
242
|
-
return (req, res, next) => {
|
|
243
|
-
const extension = path.parse(file.source).ext.substr(1);
|
|
244
|
-
const headers = ObjectUtils.merge(
|
|
245
|
-
{ 'Content-Type': mime.getType(extension) },
|
|
246
|
-
file.headers,
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
Object.keys(headers).forEach((headerName) => {
|
|
250
|
-
res.setHeader(headerName, headers[headerName]);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
this._sendFile(res, file.source, next);
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Helper method that validates and normalizes the options received by the controller.
|
|
258
|
-
*
|
|
259
|
-
* @param {StaticsControllerOptions} options The options to validate.
|
|
260
|
-
* @returns {StaticsControllerOptions}
|
|
261
|
-
* @throws {Error} If no files are specified.
|
|
262
|
-
* @throws {Error} If methods is not defined.
|
|
263
|
-
* @throws {Error} If no methods are enabled.
|
|
264
|
-
* @throws {Error} If there's an invalid HTTP method.
|
|
265
|
-
* @access protected
|
|
266
|
-
* @ignore
|
|
267
|
-
*/
|
|
268
|
-
_normalizeOptions(options) {
|
|
269
|
-
if (!options.files || !options.files.length) {
|
|
270
|
-
throw new Error('You need to specify a list of files');
|
|
271
|
-
} else if (!options.methods) {
|
|
272
|
-
throw new Error('You need to specify which HTTP methods are allowed for the files');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const methods = Object.keys(options.methods);
|
|
276
|
-
|
|
277
|
-
const atLeastOne = methods.some((method) => options.methods[method]);
|
|
278
|
-
if (!atLeastOne) {
|
|
279
|
-
throw new Error('You need to enable at least one HTTP method to serve the files');
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const allowedMethods = [
|
|
283
|
-
'all',
|
|
284
|
-
'get',
|
|
285
|
-
'head',
|
|
286
|
-
'post',
|
|
287
|
-
'put',
|
|
288
|
-
'delete',
|
|
289
|
-
'connect',
|
|
290
|
-
'options',
|
|
291
|
-
'trace',
|
|
292
|
-
];
|
|
293
|
-
|
|
294
|
-
const invalid = methods.find(
|
|
295
|
-
(method) => !allowedMethods.includes(method.toLowerCase()),
|
|
296
|
-
);
|
|
297
|
-
if (invalid) {
|
|
298
|
-
throw new Error(`${invalid} is not a valid HTTP method`);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const newMethods = methods.reduce(
|
|
302
|
-
(acc, method) => ({
|
|
303
|
-
...acc,
|
|
304
|
-
[method.toLowerCase()]: options.methods[method],
|
|
305
|
-
}),
|
|
306
|
-
{},
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
return {
|
|
310
|
-
...options,
|
|
311
|
-
methods: newMethods,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* This controller allows you to serve specific files from any folder to any route without
|
|
317
|
-
* the need of mounting directories as "static".
|
|
318
|
-
*
|
|
319
|
-
* @type {ControllerCreator<StaticsControllerWrapperOptions>}
|
|
320
|
-
* @parent module:controllers
|
|
321
|
-
*/
|
|
322
|
-
const staticsController = controllerCreator((options = {}) => (app) => {
|
|
323
|
-
const router = app.get('router');
|
|
324
|
-
const ctrl = new StaticsController(app.get('sendFile'), options);
|
|
325
|
-
let useMiddlewares;
|
|
326
|
-
if (options.middlewares) {
|
|
327
|
-
useMiddlewares = options
|
|
328
|
-
.middlewares(app)
|
|
329
|
-
.map((middleware) => (middleware.connect ? middleware.connect(app) : middleware));
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return ctrl.addRoutes(router, useMiddlewares);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
module.exports.StaticsController = StaticsController;
|
|
336
|
-
module.exports.staticsController = staticsController;
|