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.
Files changed (388) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/LICENSE +1 -1
  3. package/README.md +446 -434
  4. package/dist/app/index.d.ts +13 -0
  5. package/dist/app/index.js +19 -0
  6. package/dist/app/index.js.map +1 -0
  7. package/dist/app/jimpex.d.ts +13 -0
  8. package/dist/app/jimpex.js +440 -0
  9. package/dist/app/jimpex.js.map +1 -0
  10. package/dist/controllers/common/config.d.ts +78 -0
  11. package/dist/controllers/common/config.js +89 -0
  12. package/dist/controllers/common/config.js.map +1 -0
  13. package/dist/controllers/common/health.d.ts +82 -0
  14. package/dist/controllers/common/health.js +97 -0
  15. package/dist/controllers/common/health.js.map +1 -0
  16. package/dist/controllers/common/index.d.ts +21 -0
  17. package/dist/controllers/common/index.js +21 -0
  18. package/dist/controllers/common/index.js.map +1 -0
  19. package/dist/controllers/common/statics.d.ts +215 -0
  20. package/dist/controllers/common/statics.js +202 -0
  21. package/dist/controllers/common/statics.js.map +1 -0
  22. package/dist/controllers/index.d.ts +24 -0
  23. package/dist/controllers/index.js +20 -0
  24. package/dist/controllers/index.js.map +1 -0
  25. package/dist/controllers/utils/gateway.d.ts +724 -0
  26. package/dist/controllers/utils/gateway.js +425 -0
  27. package/dist/controllers/utils/gateway.js.map +1 -0
  28. package/dist/controllers/utils/index.d.ts +16 -0
  29. package/dist/controllers/utils/index.js +19 -0
  30. package/dist/controllers/utils/index.js.map +1 -0
  31. package/dist/esm/app/index.js +2 -0
  32. package/dist/esm/app/index.js.map +1 -0
  33. package/dist/esm/app/jimpex.js +415 -0
  34. package/dist/esm/app/jimpex.js.map +1 -0
  35. package/dist/esm/chunk-T2T6Q22Z.js +11 -0
  36. package/dist/esm/chunk-T2T6Q22Z.js.map +1 -0
  37. package/dist/esm/controllers/common/config.js +62 -0
  38. package/dist/esm/controllers/common/config.js.map +1 -0
  39. package/dist/esm/controllers/common/health.js +70 -0
  40. package/dist/esm/controllers/common/health.js.map +1 -0
  41. package/dist/esm/controllers/common/index.js +4 -0
  42. package/dist/esm/controllers/common/index.js.map +1 -0
  43. package/dist/esm/controllers/common/statics.js +173 -0
  44. package/dist/esm/controllers/common/statics.js.map +1 -0
  45. package/dist/esm/controllers/index.js +3 -0
  46. package/dist/esm/controllers/index.js.map +1 -0
  47. package/dist/esm/controllers/utils/gateway.js +404 -0
  48. package/dist/esm/controllers/utils/gateway.js.map +1 -0
  49. package/dist/esm/controllers/utils/index.js +2 -0
  50. package/dist/esm/controllers/utils/index.js.map +1 -0
  51. package/dist/esm/index.js +7 -0
  52. package/dist/esm/index.js.map +1 -0
  53. package/dist/esm/middlewares/common/errorHandler.js +92 -0
  54. package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
  55. package/dist/esm/middlewares/common/forceHTTPS.js +41 -0
  56. package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
  57. package/dist/esm/middlewares/common/hsts.js +53 -0
  58. package/dist/esm/middlewares/common/hsts.js.map +1 -0
  59. package/dist/esm/middlewares/common/index.js +4 -0
  60. package/dist/esm/middlewares/common/index.js.map +1 -0
  61. package/dist/esm/middlewares/html/fastHTML.js +104 -0
  62. package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
  63. package/dist/esm/middlewares/html/index.js +3 -0
  64. package/dist/esm/middlewares/html/index.js.map +1 -0
  65. package/dist/esm/middlewares/html/showHTML.js +68 -0
  66. package/dist/esm/middlewares/html/showHTML.js.map +1 -0
  67. package/dist/esm/middlewares/index.js +4 -0
  68. package/dist/esm/middlewares/index.js.map +1 -0
  69. package/dist/esm/middlewares/utils/index.js +2 -0
  70. package/dist/esm/middlewares/utils/index.js.map +1 -0
  71. package/dist/esm/middlewares/utils/versionValidator.js +101 -0
  72. package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
  73. package/dist/esm/services/common/appError.js +52 -0
  74. package/dist/esm/services/common/appError.js.map +1 -0
  75. package/dist/esm/services/common/httpError.js +19 -0
  76. package/dist/esm/services/common/httpError.js.map +1 -0
  77. package/dist/esm/services/common/index.js +17 -0
  78. package/dist/esm/services/common/index.js.map +1 -0
  79. package/dist/esm/services/common/sendFile.js +27 -0
  80. package/dist/esm/services/common/sendFile.js.map +1 -0
  81. package/dist/esm/services/frontend/frontendFs.js +38 -0
  82. package/dist/esm/services/frontend/frontendFs.js.map +1 -0
  83. package/dist/esm/services/frontend/index.js +11 -0
  84. package/dist/esm/services/frontend/index.js.map +1 -0
  85. package/dist/esm/services/html/htmlGenerator.js +144 -0
  86. package/dist/esm/services/html/htmlGenerator.js.map +1 -0
  87. package/dist/esm/services/html/index.js +11 -0
  88. package/dist/esm/services/html/index.js.map +1 -0
  89. package/dist/esm/services/http/apiClient.js +71 -0
  90. package/dist/esm/services/http/apiClient.js.map +1 -0
  91. package/dist/esm/services/http/http.js +125 -0
  92. package/dist/esm/services/http/http.js.map +1 -0
  93. package/dist/esm/services/http/index.js +17 -0
  94. package/dist/esm/services/http/index.js.map +1 -0
  95. package/dist/esm/services/http/responsesBuilder.js +105 -0
  96. package/dist/esm/services/http/responsesBuilder.js.map +1 -0
  97. package/dist/esm/services/index.js +6 -0
  98. package/dist/esm/services/index.js.map +1 -0
  99. package/dist/esm/services/utils/ensureBearerToken.js +78 -0
  100. package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
  101. package/dist/esm/services/utils/index.js +11 -0
  102. package/dist/esm/services/utils/index.js.map +1 -0
  103. package/dist/esm/types/events.js +1 -0
  104. package/dist/esm/types/events.js.map +1 -0
  105. package/dist/esm/types/express.js +1 -0
  106. package/dist/esm/types/express.js.map +1 -0
  107. package/dist/esm/types/http.js +1 -0
  108. package/dist/esm/types/http.js.map +1 -0
  109. package/dist/esm/types/index.js +7 -0
  110. package/dist/esm/types/index.js.map +1 -0
  111. package/dist/esm/types/options.js +1 -0
  112. package/dist/esm/types/options.js.map +1 -0
  113. package/dist/esm/types/utils.js +1 -0
  114. package/dist/esm/types/utils.js.map +1 -0
  115. package/dist/esm/types/wootils.js +1 -0
  116. package/dist/esm/types/wootils.js.map +1 -0
  117. package/dist/esm/utils/fns/index.js +5 -0
  118. package/dist/esm/utils/fns/index.js.map +1 -0
  119. package/dist/esm/utils/fns/others.js +6 -0
  120. package/dist/esm/utils/fns/others.js.map +1 -0
  121. package/dist/esm/utils/fns/routes.js +25 -0
  122. package/dist/esm/utils/fns/routes.js.map +1 -0
  123. package/dist/esm/utils/fns/statuses.js +6 -0
  124. package/dist/esm/utils/fns/statuses.js.map +1 -0
  125. package/dist/esm/utils/fns/text.js +6 -0
  126. package/dist/esm/utils/fns/text.js.map +1 -0
  127. package/dist/esm/utils/index.js +3 -0
  128. package/dist/esm/utils/index.js.map +1 -0
  129. package/dist/esm/utils/wrappers.js +41 -0
  130. package/dist/esm/utils/wrappers.js.map +1 -0
  131. package/dist/index.d.ts +46 -0
  132. package/dist/index.js +24 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/jimpex-7eaee271.d.ts +1278 -0
  135. package/dist/middlewares/common/errorHandler.d.ts +131 -0
  136. package/dist/middlewares/common/errorHandler.js +119 -0
  137. package/dist/middlewares/common/errorHandler.js.map +1 -0
  138. package/dist/middlewares/common/forceHTTPS.d.ts +68 -0
  139. package/dist/middlewares/common/forceHTTPS.js +68 -0
  140. package/dist/middlewares/common/forceHTTPS.js.map +1 -0
  141. package/dist/middlewares/common/hsts.d.ts +109 -0
  142. package/dist/middlewares/common/hsts.js +80 -0
  143. package/dist/middlewares/common/hsts.js.map +1 -0
  144. package/dist/middlewares/common/index.d.ts +21 -0
  145. package/dist/middlewares/common/index.js +21 -0
  146. package/dist/middlewares/common/index.js.map +1 -0
  147. package/dist/middlewares/html/fastHTML.d.ts +180 -0
  148. package/dist/middlewares/html/fastHTML.js +131 -0
  149. package/dist/middlewares/html/fastHTML.js.map +1 -0
  150. package/dist/middlewares/html/index.d.ts +21 -0
  151. package/dist/middlewares/html/index.js +20 -0
  152. package/dist/middlewares/html/index.js.map +1 -0
  153. package/dist/middlewares/html/showHTML.d.ts +127 -0
  154. package/dist/middlewares/html/showHTML.js +95 -0
  155. package/dist/middlewares/html/showHTML.js.map +1 -0
  156. package/dist/middlewares/index.d.ts +30 -0
  157. package/dist/middlewares/index.js +21 -0
  158. package/dist/middlewares/index.js.map +1 -0
  159. package/dist/middlewares/utils/index.d.ts +19 -0
  160. package/dist/middlewares/utils/index.js +19 -0
  161. package/dist/middlewares/utils/index.js.map +1 -0
  162. package/dist/middlewares/utils/versionValidator.d.ts +214 -0
  163. package/dist/middlewares/utils/versionValidator.js +128 -0
  164. package/dist/middlewares/utils/versionValidator.js.map +1 -0
  165. package/dist/services/common/appError.d.ts +138 -0
  166. package/dist/services/common/appError.js +80 -0
  167. package/dist/services/common/appError.js.map +1 -0
  168. package/dist/services/common/httpError.d.ts +79 -0
  169. package/dist/services/common/httpError.js +44 -0
  170. package/dist/services/common/httpError.js.map +1 -0
  171. package/dist/services/common/index.d.ts +47 -0
  172. package/dist/services/common/index.js +41 -0
  173. package/dist/services/common/index.js.map +1 -0
  174. package/dist/services/common/sendFile.d.ts +102 -0
  175. package/dist/services/common/sendFile.js +51 -0
  176. package/dist/services/common/sendFile.js.map +1 -0
  177. package/dist/services/frontend/frontendFs.d.ts +96 -0
  178. package/dist/services/frontend/frontendFs.js +71 -0
  179. package/dist/services/frontend/frontendFs.js.map +1 -0
  180. package/dist/services/frontend/index.d.ts +40 -0
  181. package/dist/services/frontend/index.js +35 -0
  182. package/dist/services/frontend/index.js.map +1 -0
  183. package/dist/services/html/htmlGenerator.d.ts +237 -0
  184. package/dist/services/html/htmlGenerator.js +171 -0
  185. package/dist/services/html/htmlGenerator.js.map +1 -0
  186. package/dist/services/html/index.d.ts +43 -0
  187. package/dist/services/html/index.js +35 -0
  188. package/dist/services/html/index.js.map +1 -0
  189. package/dist/services/http/apiClient.d.ts +169 -0
  190. package/dist/services/http/apiClient.js +96 -0
  191. package/dist/services/http/apiClient.js.map +1 -0
  192. package/dist/services/http/http.d.ts +175 -0
  193. package/dist/services/http/http.js +158 -0
  194. package/dist/services/http/http.js.map +1 -0
  195. package/dist/services/http/index.d.ts +50 -0
  196. package/dist/services/http/index.js +41 -0
  197. package/dist/services/http/index.js.map +1 -0
  198. package/dist/services/http/responsesBuilder.d.ts +178 -0
  199. package/dist/services/http/responsesBuilder.js +132 -0
  200. package/dist/services/http/responsesBuilder.js.map +1 -0
  201. package/dist/services/index.d.ts +33 -0
  202. package/dist/services/index.js +23 -0
  203. package/dist/services/index.js.map +1 -0
  204. package/dist/services/utils/ensureBearerToken.d.ts +157 -0
  205. package/dist/services/utils/ensureBearerToken.js +105 -0
  206. package/dist/services/utils/ensureBearerToken.js.map +1 -0
  207. package/dist/services/utils/index.d.ts +43 -0
  208. package/dist/services/utils/index.js +35 -0
  209. package/dist/services/utils/index.js.map +1 -0
  210. package/dist/types/events.d.ts +13 -0
  211. package/dist/types/events.js +17 -0
  212. package/dist/types/events.js.map +1 -0
  213. package/dist/types/express.d.ts +10 -0
  214. package/dist/types/express.js +17 -0
  215. package/dist/types/express.js.map +1 -0
  216. package/dist/types/http.d.ts +79 -0
  217. package/dist/types/http.js +17 -0
  218. package/dist/types/http.js.map +1 -0
  219. package/dist/types/index.d.ts +14 -0
  220. package/dist/types/index.js +24 -0
  221. package/dist/types/index.js.map +1 -0
  222. package/dist/types/options.d.ts +13 -0
  223. package/dist/types/options.js +17 -0
  224. package/dist/types/options.js.map +1 -0
  225. package/dist/types/utils.d.ts +48 -0
  226. package/dist/types/utils.js +17 -0
  227. package/dist/types/utils.js.map +1 -0
  228. package/dist/types/wootils.d.ts +4 -0
  229. package/dist/types/wootils.js +17 -0
  230. package/dist/types/wootils.js.map +1 -0
  231. package/dist/utils/fns/index.d.ts +5 -0
  232. package/dist/utils/fns/index.js +22 -0
  233. package/dist/utils/fns/index.js.map +1 -0
  234. package/dist/utils/fns/others.d.ts +17 -0
  235. package/dist/utils/fns/others.js +29 -0
  236. package/dist/utils/fns/others.js.map +1 -0
  237. package/dist/utils/fns/routes.d.ts +39 -0
  238. package/dist/utils/fns/routes.js +51 -0
  239. package/dist/utils/fns/routes.js.map +1 -0
  240. package/dist/utils/fns/statuses.d.ts +45 -0
  241. package/dist/utils/fns/statuses.js +35 -0
  242. package/dist/utils/fns/statuses.js.map +1 -0
  243. package/dist/utils/fns/text.d.ts +9 -0
  244. package/dist/utils/fns/text.js +29 -0
  245. package/dist/utils/fns/text.js.map +1 -0
  246. package/dist/utils/index.d.ts +18 -0
  247. package/dist/utils/index.js +20 -0
  248. package/dist/utils/index.js.map +1 -0
  249. package/dist/utils/wrappers.d.ts +13 -0
  250. package/dist/utils/wrappers.js +68 -0
  251. package/dist/utils/wrappers.js.map +1 -0
  252. package/examples/basic/404.html +12 -0
  253. package/examples/basic/README.md +30 -0
  254. package/examples/basic/app.ts +18 -0
  255. package/examples/basic/controller.ts +45 -0
  256. package/examples/basic/index.ts +19 -0
  257. package/examples/basic/middleware.ts +13 -0
  258. package/examples/basic/service.ts +11 -0
  259. package/package.json +59 -38
  260. package/src/app/index.ts +1 -0
  261. package/src/app/jimpex.ts +743 -0
  262. package/src/controllers/common/config.ts +115 -0
  263. package/src/controllers/common/health.ts +128 -0
  264. package/src/controllers/common/index.ts +3 -0
  265. package/src/controllers/common/statics.ts +380 -0
  266. package/src/controllers/index.ts +2 -0
  267. package/src/controllers/utils/gateway.ts +1186 -0
  268. package/src/controllers/utils/index.ts +1 -0
  269. package/src/index.ts +6 -0
  270. package/src/middlewares/common/errorHandler.ts +203 -0
  271. package/src/middlewares/common/forceHTTPS.ts +83 -0
  272. package/src/middlewares/common/hsts.ts +135 -0
  273. package/src/middlewares/common/index.ts +3 -0
  274. package/src/middlewares/html/fastHTML.ts +255 -0
  275. package/src/middlewares/html/index.ts +2 -0
  276. package/src/middlewares/html/showHTML.ts +165 -0
  277. package/src/middlewares/index.ts +3 -0
  278. package/src/middlewares/utils/index.ts +1 -0
  279. package/src/middlewares/utils/versionValidator.ts +289 -0
  280. package/src/services/common/appError.ts +158 -0
  281. package/src/services/common/httpError.ts +74 -0
  282. package/src/services/common/index.ts +29 -0
  283. package/src/services/common/sendFile.ts +106 -0
  284. package/src/services/frontend/frontendFs.ts +101 -0
  285. package/src/services/frontend/index.ts +21 -0
  286. package/src/services/html/htmlGenerator.ts +356 -0
  287. package/src/services/html/index.ts +21 -0
  288. package/src/services/http/apiClient.ts +221 -0
  289. package/src/services/http/http.ts +286 -0
  290. package/src/services/http/index.ts +29 -0
  291. package/src/services/http/responsesBuilder.ts +265 -0
  292. package/src/services/index.ts +5 -0
  293. package/src/services/utils/ensureBearerToken.ts +202 -0
  294. package/src/services/utils/index.ts +21 -0
  295. package/src/types/events.ts +303 -0
  296. package/src/types/express.ts +21 -0
  297. package/src/types/http.ts +77 -0
  298. package/src/types/index.ts +6 -0
  299. package/src/types/options.ts +248 -0
  300. package/src/types/utils.ts +52 -0
  301. package/src/types/wootils.ts +4 -0
  302. package/src/utils/fns/index.ts +4 -0
  303. package/src/utils/fns/others.ts +15 -0
  304. package/src/utils/fns/routes.ts +64 -0
  305. package/src/utils/fns/statuses.ts +44 -0
  306. package/src/utils/fns/text.ts +8 -0
  307. package/src/utils/index.ts +2 -0
  308. package/src/utils/wrappers.ts +537 -0
  309. package/tsconfig.json +5 -8
  310. package/tsup.config.ts +10 -0
  311. package/src/app/index.js +0 -692
  312. package/src/constants/eventNames.js +0 -48
  313. package/src/constants/index.js +0 -7
  314. package/src/controllers/common/configuration.js +0 -116
  315. package/src/controllers/common/health.js +0 -79
  316. package/src/controllers/common/index.js +0 -7
  317. package/src/controllers/common/statics.js +0 -336
  318. package/src/controllers/index.js +0 -9
  319. package/src/controllers/utils/gateway.js +0 -1039
  320. package/src/controllers/utils/index.js +0 -3
  321. package/src/index.js +0 -30
  322. package/src/middlewares/common/errorHandler.js +0 -185
  323. package/src/middlewares/common/forceHTTPS.js +0 -80
  324. package/src/middlewares/common/hsts.js +0 -122
  325. package/src/middlewares/common/index.js +0 -7
  326. package/src/middlewares/html/fastHTML.js +0 -298
  327. package/src/middlewares/html/index.js +0 -5
  328. package/src/middlewares/html/showHTML.js +0 -167
  329. package/src/middlewares/index.js +0 -11
  330. package/src/middlewares/utils/index.js +0 -3
  331. package/src/middlewares/utils/versionValidator.js +0 -261
  332. package/src/services/common/appError.js +0 -136
  333. package/src/services/common/httpError.js +0 -60
  334. package/src/services/common/index.js +0 -25
  335. package/src/services/common/sendFile.js +0 -68
  336. package/src/services/frontend/frontendFs.js +0 -85
  337. package/src/services/frontend/index.js +0 -17
  338. package/src/services/html/htmlGenerator.js +0 -391
  339. package/src/services/html/index.js +0 -17
  340. package/src/services/http/apiClient.js +0 -148
  341. package/src/services/http/http.js +0 -256
  342. package/src/services/http/index.js +0 -25
  343. package/src/services/http/responsesBuilder.js +0 -193
  344. package/src/services/index.js +0 -15
  345. package/src/services/utils/ensureBearerToken.js +0 -147
  346. package/src/services/utils/index.js +0 -19
  347. package/src/types.js +0 -377
  348. package/src/utils/functions.js +0 -78
  349. package/src/utils/wrappers.js +0 -131
  350. package/types/app/index.d.ts +0 -417
  351. package/types/constants/eventNames.d.ts +0 -93
  352. package/types/constants/index.d.ts +0 -2
  353. package/types/controllers/common/configuration.d.ts +0 -71
  354. package/types/controllers/common/health.d.ts +0 -55
  355. package/types/controllers/common/index.d.ts +0 -4
  356. package/types/controllers/common/statics.d.ts +0 -271
  357. package/types/controllers/index.d.ts +0 -3
  358. package/types/controllers/utils/gateway.d.ts +0 -947
  359. package/types/controllers/utils/index.d.ts +0 -2
  360. package/types/index.d.ts +0 -15
  361. package/types/middlewares/common/errorHandler.d.ts +0 -143
  362. package/types/middlewares/common/forceHTTPS.d.ts +0 -64
  363. package/types/middlewares/common/hsts.d.ts +0 -111
  364. package/types/middlewares/common/index.d.ts +0 -4
  365. package/types/middlewares/html/fastHTML.d.ts +0 -238
  366. package/types/middlewares/html/index.d.ts +0 -3
  367. package/types/middlewares/html/showHTML.d.ts +0 -128
  368. package/types/middlewares/index.d.ts +0 -4
  369. package/types/middlewares/utils/index.d.ts +0 -2
  370. package/types/middlewares/utils/versionValidator.d.ts +0 -247
  371. package/types/services/common/appError.d.ts +0 -89
  372. package/types/services/common/httpError.d.ts +0 -37
  373. package/types/services/common/index.d.ts +0 -18
  374. package/types/services/common/sendFile.d.ts +0 -56
  375. package/types/services/frontend/frontendFs.d.ts +0 -72
  376. package/types/services/frontend/index.d.ts +0 -3
  377. package/types/services/html/htmlGenerator.d.ts +0 -298
  378. package/types/services/html/index.d.ts +0 -3
  379. package/types/services/http/apiClient.d.ts +0 -141
  380. package/types/services/http/http.d.ts +0 -159
  381. package/types/services/http/index.d.ts +0 -18
  382. package/types/services/http/responsesBuilder.d.ts +0 -140
  383. package/types/services/index.d.ts +0 -6
  384. package/types/services/utils/ensureBearerToken.d.ts +0 -137
  385. package/types/services/utils/index.d.ts +0 -16
  386. package/types/types.d.ts +0 -280
  387. package/types/utils/functions.d.ts +0 -55
  388. package/types/utils/wrappers.d.ts +0 -127
@@ -0,0 +1,743 @@
1
+ import * as path from 'path';
2
+ import fs from 'fs/promises';
3
+ import { createServer as createHTTPSServer } from 'https';
4
+ import { Jimple } from '@homer0/jimple';
5
+ import { deepAssignWithOverwrite } from '@homer0/deep-assign';
6
+ import { appLoggerProvider } from '@homer0/simple-logger';
7
+ import { envUtilsProvider } from '@homer0/env-utils';
8
+ import { packageInfoProvider } from '@homer0/package-info';
9
+ import { pathUtilsProvider } from '@homer0/path-utils';
10
+ import { rootFileProvider } from '@homer0/root-file';
11
+ import { EventsHub } from '@homer0/events-hub';
12
+ import { simpleConfigProvider } from '@homer0/simple-config';
13
+ import compression from 'compression';
14
+ import bodyParser from 'body-parser';
15
+ import multer from 'multer';
16
+ import {
17
+ createServer as createSpdyServer,
18
+ type ServerOptions as SpdyServerOptions,
19
+ } from 'spdy';
20
+ import express from 'express';
21
+ import {
22
+ commonServicesProvider,
23
+ httpServicesProvider,
24
+ utilsServicesProvider,
25
+ } from '../services';
26
+ import {
27
+ statuses,
28
+ type Controller,
29
+ type ControllerLike,
30
+ type MiddlewareLike,
31
+ type MiddlewareProvider,
32
+ type Middleware,
33
+ } from '../utils';
34
+ import type {
35
+ DeepPartial,
36
+ Express,
37
+ ExpressMiddlewareLike,
38
+ PathUtils,
39
+ Config,
40
+ Logger,
41
+ JimpexOptions,
42
+ JimpexHTTPSCredentials,
43
+ JimpexHTTP2Options,
44
+ JimpexHTTPSOptions,
45
+ JimpexStartCallback,
46
+ JimpexServer,
47
+ JimpexServerInstance,
48
+ JimpexEventName,
49
+ JimpexEventPayload,
50
+ DeepReadonly,
51
+ JimpexReducerEventName,
52
+ JimpexReducerEventPayload,
53
+ JimpexReducerEventTarget,
54
+ JimpexEventNameLike,
55
+ JimpexEventListener,
56
+ JimpexHealthCheckFn,
57
+ Router,
58
+ } from '../types';
59
+ /**
60
+ * Jimpex is a mix of Jimple, a Javascript port of Pimple dependency injection container,
61
+ * and Express, one of the most popular web frameworks for Node.
62
+ *
63
+ * @group Jimpex
64
+ * @todo Implement `helmet`.
65
+ */
66
+ export class Jimpex extends Jimple {
67
+ /**
68
+ * The customization settings for the application.
69
+ */
70
+ protected _options: JimpexOptions;
71
+ /**
72
+ * The Express application Jimpex uses under the hood.
73
+ */
74
+ protected _express: Express;
75
+ /**
76
+ * Since the configuration service has an async initialization, the class uses this flag
77
+ * internally to validate if the configuration has been initialized or not.
78
+ */
79
+ protected _configReady: boolean = false;
80
+ /**
81
+ * A reference to the actuall HTTP the application will use. This can vary depending on
82
+ * whether HTTPS, or HTTP2 are enabled. If HTTPS is not enabled, it will be the same as
83
+ * the `express` property; if HTTPS is enabled, it will be an `https` server; and if
84
+ * HTTP2 is enabled, it will be an `spdy` server.
85
+ */
86
+ protected _server?: JimpexServer;
87
+ /**
88
+ * The instance of the server that is listening for requests.
89
+ */
90
+ protected _instance?: JimpexServerInstance;
91
+ /**
92
+ * A list of functions that implement controllers and middlewares. When the application
93
+ * starts, the queue will be processed and those controllers and middlewares will be
94
+ * added to the server instance. The reason they are not added directly like with a
95
+ * regular Express implementation is that services on Jimple use lazy loading, and
96
+ * adding middlewares and controllers as they come could cause errors if they depend on
97
+ * services that are not yet registered.
98
+ */
99
+ protected _mountQueue: Array<(server: Express) => void> = [];
100
+ /**
101
+ * A list with all the top routes controlled by the application. Every time a controller
102
+ * is mounted, its route will be added here.
103
+ */
104
+ protected _controlledRoutes: string[] = [];
105
+ /**
106
+ * @param options Preferences to customize the application.
107
+ * @param config The default settings for the configuration service. It's a
108
+ * shortcuit for `options.config.default`
109
+ */
110
+ constructor(options: DeepPartial<JimpexOptions> = {}, config: unknown = {}) {
111
+ super();
112
+
113
+ this._options = deepAssignWithOverwrite(
114
+ {
115
+ filesizeLimit: '15MB',
116
+ boot: true,
117
+ path: {
118
+ appPath: '',
119
+ useParentPath: true,
120
+ },
121
+ config: {
122
+ default: options?.config?.default || config,
123
+ name: 'app',
124
+ path: 'config/',
125
+ hasFolder: false,
126
+ loadFromEnvironment: true,
127
+ environmentVariable: 'CONFIG',
128
+ defaultConfigFilename: '[app-name].config.js',
129
+ filenameFormat: '[app-name].[config-name].config.js',
130
+ },
131
+ statics: {
132
+ enabled: true,
133
+ onHome: false,
134
+ route: 'statics',
135
+ },
136
+ express: {
137
+ trustProxy: true,
138
+ disableXPoweredBy: true,
139
+ compression: true,
140
+ bodyParser: true,
141
+ multer: true,
142
+ },
143
+ services: {
144
+ common: true,
145
+ http: true,
146
+ utils: true,
147
+ },
148
+ healthCheck: () => Promise.resolve(true),
149
+ },
150
+ options,
151
+ this._initOptions(),
152
+ );
153
+
154
+ this._express = express();
155
+
156
+ this._setupCoreServices();
157
+ this._setupExpress();
158
+ this._configurePath();
159
+
160
+ this._init();
161
+ if (this._options.boot) {
162
+ this.boot();
163
+ }
164
+ }
165
+ /**
166
+ * This is where the app would register all its specific services, middlewares and controllers.
167
+ */
168
+ boot(): void {}
169
+ /**
170
+ * Disables the server TLS validation. Meant to be used for development purposes.
171
+ */
172
+ disableTLSValidation() {
173
+ // eslint-disable-next-line no-process-env, dot-notation
174
+ process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
175
+ this.logger.warn('TLS validation has been disabled');
176
+ }
177
+ /**
178
+ * Starts the app server.
179
+ *
180
+ * @param onStart A callback function to be called when the server actually starts.
181
+ * @returns The server instance.
182
+ */
183
+ async start(onStart?: JimpexStartCallback): Promise<JimpexServerInstance> {
184
+ await this._setupConfig();
185
+ const config = this.getConfig();
186
+ const port = config.get<number | undefined>('port');
187
+ if (!port) {
188
+ throw new Error('No port configured');
189
+ }
190
+ this._emitEvent('beforeStart', { app: this });
191
+ this._server = await this._createServer();
192
+ this._instance = this._server!.listen(port, () => {
193
+ this._emitEvent('start', { app: this });
194
+ this._mountResources();
195
+ this.logger.success(`Starting on port ${port}`);
196
+ this._emitEvent('afterStart', { app: this });
197
+ if (onStart) {
198
+ onStart(config);
199
+ }
200
+ this._emitEvent('afterStartCallback', { app: this });
201
+ });
202
+
203
+ return this._instance!;
204
+ }
205
+ /**
206
+ * This is an alias of `start`. The idea is for it to be used on serverless platforms,
207
+ * where you don't get to start your app, you just have export it.
208
+ *
209
+ * @param port In case the configuration doesn't already have it,
210
+ * this is the port where the application will use to run. If this
211
+ * parameter is used, the method will overwrite the `port`
212
+ * setting on the configuration service.
213
+ * @param onStart A callback function to be called when the server starts.
214
+ * @returns The server instance.
215
+ */
216
+ async listen(
217
+ port?: number,
218
+ onStart?: JimpexStartCallback,
219
+ ): Promise<JimpexServerInstance> {
220
+ if (port) {
221
+ await this._setupConfig();
222
+ const config = this.getConfig();
223
+ config.set('port', port);
224
+ }
225
+
226
+ return this.start(onStart);
227
+ }
228
+ /**
229
+ * Stops the server instance.
230
+ */
231
+ stop(): void {
232
+ if (!this._instance) return;
233
+ this._emitEvent('beforeStop', { app: this });
234
+ this._instance.close();
235
+ this._instance = undefined;
236
+ this._emitEvent('afterStop', { app: this });
237
+ }
238
+ /**
239
+ * Mounts a route controller or a middleware into a server routes.
240
+ *
241
+ * @param route The route for the controller/middleware.
242
+ * @param controller The controller/middleware resource to be mounted.
243
+ */
244
+ mount(route: string, controller: ControllerLike): void {
245
+ let useController: Controller | Middleware;
246
+ if (
247
+ 'register' in controller &&
248
+ typeof controller.register === 'function' &&
249
+ controller.provider === true
250
+ ) {
251
+ useController = controller.register(this, route);
252
+ } else if (
253
+ 'connect' in controller &&
254
+ typeof controller.connect === 'function' &&
255
+ (('middleware' in controller && controller.middleware === true) ||
256
+ ('controller' in controller && controller.controller === true))
257
+ ) {
258
+ useController = controller;
259
+ } else {
260
+ useController = {
261
+ middleware: true,
262
+ connect: () => controller as ExpressMiddlewareLike,
263
+ };
264
+ }
265
+
266
+ this._mountQueue.push((server) => {
267
+ const connected = useController.connect(this, route);
268
+ if (!connected) return;
269
+ const router = this._reduceWithEvent('controllerWillBeMounted', connected, {
270
+ route,
271
+ controller: useController,
272
+ app: this,
273
+ });
274
+ server.use(route, router);
275
+ this._emitEvent('routeAdded', { route, app: this });
276
+ this._controlledRoutes.push(route);
277
+ });
278
+ }
279
+ /**
280
+ * Adds a global middleware to the application.
281
+ *
282
+ * @param middleware The middleware resource to be added.
283
+ */
284
+ use(middleware: MiddlewareLike): void {
285
+ const useMiddleware =
286
+ 'register' in middleware && typeof middleware.register === 'function'
287
+ ? (middleware as MiddlewareProvider).register(this)
288
+ : (middleware as Middleware | ExpressMiddlewareLike);
289
+ this._mountQueue.push((server) => {
290
+ if ('connect' in useMiddleware && typeof useMiddleware.connect === 'function') {
291
+ const handler = useMiddleware.connect(this);
292
+ if (handler) {
293
+ server.use(
294
+ this._reduceWithEvent('middlewareWillBeUsed', handler, { app: this }),
295
+ );
296
+ }
297
+
298
+ return;
299
+ }
300
+
301
+ server.use(
302
+ this._reduceWithEvent(
303
+ 'middlewareWillBeUsed',
304
+ useMiddleware as ExpressMiddlewareLike,
305
+ { app: this },
306
+ ),
307
+ );
308
+ });
309
+ }
310
+
311
+ getConfig(): Config;
312
+ getConfig<T = unknown>(setting: string | string[], asArray?: boolean): T;
313
+ /**
314
+ * Gets a setting from the configuration, or the configuration itself.
315
+ *
316
+ * @param setting The setting or settings to be retrieved. If is not specified, it
317
+ * will return the entire configuration.
318
+ * @param asArray If `true` and `setting` is an array, it will return the values as
319
+ * an array instead of an object.
320
+ * @template T The type of the setting to be retrieved.
321
+ */
322
+ getConfig<T = unknown>(
323
+ setting?: string | string[],
324
+ asArray: boolean = false,
325
+ ): Config | T {
326
+ const config = this.try<Config>('config');
327
+ if (!config) {
328
+ throw new Error('The config service is not available until the app starts');
329
+ }
330
+ if (typeof setting === 'undefined') {
331
+ return config;
332
+ }
333
+
334
+ return config.get<T>(setting, asArray);
335
+ }
336
+ /**
337
+ * Creates a new router instance.
338
+ */
339
+ getRouter(): Router {
340
+ return this.get('router');
341
+ }
342
+ /**
343
+ * The logger service.
344
+ */
345
+ get logger(): Logger {
346
+ return this.get<Logger>('logger');
347
+ }
348
+ /**
349
+ * The Express application Jimpex uses under the hood.
350
+ */
351
+ get express(): Express {
352
+ return this._express;
353
+ }
354
+ /**
355
+ * The server instance that gets created when the app is started.
356
+ */
357
+ get instance(): JimpexServerInstance | undefined {
358
+ return this._instance;
359
+ }
360
+ /**
361
+ * The application customization options.
362
+ */
363
+ get options(): DeepReadonly<JimpexOptions> {
364
+ return deepAssignWithOverwrite({}, this._options);
365
+ }
366
+ /**
367
+ * Gets the events service.
368
+ */
369
+ get eventsHub(): EventsHub {
370
+ return this.get<EventsHub>('events');
371
+ }
372
+ /**
373
+ * A list of the routes that have controllers mounted on them.
374
+ */
375
+ get routes(): string[] {
376
+ return this._controlledRoutes.slice();
377
+ }
378
+ /**
379
+ * Adds a listener for an application event.
380
+ *
381
+ * @param eventName The name of the event to listen for.
382
+ * @param listener The listener function.
383
+ * @returns A function to unsubscribe the listener.
384
+ * @template EventName The name of the event, to match the type of the listener
385
+ * function.
386
+ */
387
+ on<EventName extends JimpexEventNameLike>(
388
+ eventName: EventName,
389
+ listener: JimpexEventListener<EventName>,
390
+ ): () => boolean {
391
+ return this.eventsHub.on(eventName, listener);
392
+ }
393
+ /**
394
+ * Adds a listener for an application event that will only be execuded once: the first
395
+ * time the event is triggered.
396
+ *
397
+ * @param eventName The name of the event to listen for.
398
+ * @param listener The listener function.
399
+ * @returns A function to unsubscribe the listener.
400
+ * @template EventName The name of the event, to match the type of the listener
401
+ * function.
402
+ */
403
+ once<EventName extends JimpexEventNameLike>(
404
+ eventName: EventName,
405
+ listener: JimpexEventListener<EventName>,
406
+ ): () => boolean {
407
+ return this.eventsHub.once(eventName, listener);
408
+ }
409
+ /**
410
+ * Based on the application options, it returns wheter the application is healthy or
411
+ * not.
412
+ */
413
+ isHealthy(): ReturnType<JimpexHealthCheckFn> {
414
+ return this._options.healthCheck(this);
415
+ }
416
+ /**
417
+ * This method is like a "lifecycle method", it gets executed on the constructor right
418
+ * before the "boot step". The idea is for the method to be a helper when the
419
+ * application is defined by subclassing {@link Jimpex}: the application could register
420
+ * all important services here and the routes on boot, then, if the implementation needs
421
+ * to access or overwrite a something, it can send `boot: false`, access/register what
422
+ * it needs, and then call `boot()`. That would be impossible for an application without
423
+ * overwriting the constructor and the boot functionality.
424
+ */
425
+ protected _init(): void {}
426
+ /**
427
+ * It generates overwrites for the application options when it gets created. This method
428
+ * is a helper for when the application is defined by subclassing {@link Jimpex}: It's
429
+ * highly probable that if the application needs to change the default options, it would
430
+ * want to do it right from the class, instead of having to do it on every
431
+ * implementation. A way to do it would be overwriting the constructor and calling
432
+ * `super` with the custom overwrites, but this method exists so that won't be
433
+ * necessary: when creating the `options`, the constructor will merge the result of this
434
+ * method on top of the default ones.
435
+ */
436
+ protected _initOptions(): DeepPartial<JimpexOptions> {
437
+ return {};
438
+ }
439
+ /**
440
+ * Registers the "core services" on the container: logger, events, utils, etc.
441
+ */
442
+ protected _setupCoreServices(): void {
443
+ this.register(
444
+ appLoggerProvider({
445
+ serviceName: 'logger',
446
+ }),
447
+ );
448
+ this.register(envUtilsProvider);
449
+ this.register(packageInfoProvider);
450
+ this.register(pathUtilsProvider);
451
+ this.register(rootFileProvider);
452
+ const { services: enabledServices } = this._options;
453
+ if (enabledServices.common) this.register(commonServicesProvider);
454
+ if (enabledServices.http) this.register(httpServicesProvider);
455
+ if (enabledServices.utils) this.register(utilsServicesProvider);
456
+
457
+ this.set('events', () => new EventsHub());
458
+ this.set('statuses', () => statuses);
459
+ }
460
+ /**
461
+ * Configures the Express application based on the class options.
462
+ */
463
+ protected _setupExpress(): void {
464
+ const { statics, filesizeLimit, express: expressOptions } = this._options;
465
+ if (expressOptions.trustProxy) {
466
+ this._express.enable('trust proxy');
467
+ }
468
+
469
+ if (expressOptions.disableXPoweredBy) {
470
+ this._express.disable('x-powered-by');
471
+ }
472
+
473
+ if (expressOptions.compression) {
474
+ this._express.use(compression());
475
+ }
476
+
477
+ if (statics.enabled) {
478
+ this._addStaticsFolder(statics.route, statics.folder, statics.onHome);
479
+ }
480
+
481
+ if (expressOptions.bodyParser) {
482
+ this._express.use(
483
+ bodyParser.json({
484
+ limit: filesizeLimit,
485
+ }),
486
+ );
487
+ this._express.use(
488
+ bodyParser.urlencoded({
489
+ extended: true,
490
+ limit: filesizeLimit,
491
+ }),
492
+ );
493
+ }
494
+
495
+ if (expressOptions.multer) {
496
+ this._express.use(multer().any());
497
+ }
498
+
499
+ this.set(
500
+ 'router',
501
+ this.factory(() => express.Router()),
502
+ );
503
+ }
504
+ /**
505
+ * Adds a static folder to the application.
506
+ *
507
+ * @param route The route to add the folder to.
508
+ * @param folder The path to the folder in the file system. If not defined, it will
509
+ * be use the same value as `route`. The path could be relative to the
510
+ * project root, or where the application executable is located,
511
+ * depending on the value of the `onHome` parameter.
512
+ * @param onHome If `true`, the path to the folder will be relative to the project
513
+ * root. If `false`, it will be relative to where the application
514
+ * executable is located.
515
+ */
516
+ protected _addStaticsFolder(
517
+ route: string,
518
+ folder: string = '',
519
+ onHome: boolean = false,
520
+ ) {
521
+ const location = onHome ? 'home' : 'app';
522
+ const staticRoute = route.replace(/^\/+/, '');
523
+ const pathUtils = this.get<PathUtils>('pathUtils');
524
+ const staticFolder = pathUtils.joinFrom(location, folder || staticRoute);
525
+ this.mount(`/${staticRoute}`, {
526
+ connect: () => express.static(staticFolder),
527
+ controller: true,
528
+ });
529
+ }
530
+ /**
531
+ * This helper method validates the `path` options in order to register the `app`
532
+ * location in the `pathUtils` service. The `app` location should be the path to where
533
+ * the application executable is located, but due to how ESM works, we can't infer it
534
+ * from the `module` object, so we need either recieved as the `appPath` setting, or try
535
+ * to get it from the parent module.
536
+ *
537
+ * @throws If the method should use the path from the parent module, but can't find
538
+ * it.
539
+ */
540
+ protected _configurePath(): void {
541
+ const pathUtils = this.get<PathUtils>('pathUtils');
542
+ const {
543
+ path: { appPath, useParentPath },
544
+ } = this._options;
545
+ if (appPath) {
546
+ pathUtils.addLocation('app', appPath);
547
+ return;
548
+ }
549
+ let foundPath = false;
550
+ if (useParentPath) {
551
+ const stack = new Error().stack!;
552
+ const stackList = stack.split('\n');
553
+ stackList.shift();
554
+ const parentFromStack = stackList.find((line) => !line.includes(__filename));
555
+ if (parentFromStack) {
556
+ const parentFile = parentFromStack.replace(/^.*?\s\(([^\s]+):\d+:\d+\)/, '$1');
557
+ if (parentFile !== parentFromStack) {
558
+ foundPath = true;
559
+ pathUtils.addLocation('app', path.dirname(parentFile));
560
+ }
561
+ }
562
+ }
563
+
564
+ if (!foundPath) {
565
+ throw new Error(
566
+ 'The app location cannot be determined. Please specify the appPath option.',
567
+ );
568
+ }
569
+ }
570
+ /**
571
+ * Setups the configuration service. The new configuration service requires async calls
572
+ * in order to load the configuration files (as it uses `import` instead of `require`),
573
+ * so it can't be instantiated as the other services.
574
+ * This method is called just before starting the application.
575
+ */
576
+ protected async _setupConfig(): Promise<void> {
577
+ if (this._configReady) return;
578
+ this._configReady = true;
579
+ const { config: options } = this._options;
580
+
581
+ let configsPath = options.path.replace(/\/$/, '');
582
+ if (options.hasFolder) {
583
+ configsPath = `${configsPath}${path.sep}${options.name}${path.sep}`;
584
+ }
585
+
586
+ const filenameFormat = options.filenameFormat
587
+ .replace(/\[app-name\]/gi, options.name)
588
+ .replace(/\[config-name\]/gi, '[name]');
589
+ const defaultConfigFilename = options.defaultConfigFilename.replace(
590
+ /\[app-name\]/gi,
591
+ options.name,
592
+ );
593
+
594
+ this.register(
595
+ simpleConfigProvider({
596
+ name: options.name,
597
+ defaultConfig: options.default,
598
+ defaultConfigFilename,
599
+ envVarName: options.environmentVariable,
600
+ path: configsPath,
601
+ filenameFormat,
602
+ }),
603
+ );
604
+
605
+ const config = this.getConfig();
606
+ await config.loadFromFile('', true, false);
607
+ if (options.loadFromEnvironment) {
608
+ await config.loadFromEnv();
609
+ }
610
+ }
611
+ /**
612
+ * Processes the resources from the mount queue (added with {@link Jimpex.mount} and
613
+ * {@link Jimpex.use}), and adds them to the Express application.
614
+ */
615
+ protected _mountResources(): void {
616
+ this._mountQueue.forEach((mount) => mount(this._express));
617
+ this._mountQueue.length = 0;
618
+ }
619
+ /**
620
+ * Emits an event using the `events` service.
621
+ *
622
+ * @param name The name of the event to emit.
623
+ * @param payload The event payload.
624
+ * @template EventName The literal name of the event, to type the event payload.
625
+ */
626
+ protected _emitEvent<EventName extends JimpexEventName>(
627
+ name: EventName,
628
+ payload: JimpexEventPayload<EventName>,
629
+ ): void {
630
+ this.eventsHub.emit(name, payload);
631
+ }
632
+ /**
633
+ * Sends a target object to a list of reducer events so they can modify or replace it.
634
+ *
635
+ * @param name The name of the event to use.
636
+ * @param target The object to reduce with the event.
637
+ * @param payload Extra context for the listeners.
638
+ */
639
+ protected _reduceWithEvent<EventName extends JimpexReducerEventName>(
640
+ name: EventName,
641
+ target: JimpexReducerEventTarget<EventName>,
642
+ payload: JimpexReducerEventPayload<EventName>,
643
+ ): JimpexReducerEventTarget<EventName> {
644
+ return this.eventsHub.reduceSync(name, target, payload);
645
+ }
646
+ /**
647
+ * Loads the contents of a dictionary of credentials files that need to be used to
648
+ * configure HTTPS.
649
+ *
650
+ * @param credentialsInfo The dictionary where the keys are the type of credentials
651
+ * (`ca`, `cert`, `key`) and the values are the paths to the
652
+ * files.
653
+ * @param onHome If this is `true`, the path of the files will be relative
654
+ * to the project root. If it is `false`, it will be relative
655
+ * to where the application executable is located.
656
+ * @returns
657
+ */
658
+ protected async _loadCredentials(
659
+ credentialsInfo: JimpexHTTPSCredentials,
660
+ onHome: boolean = true,
661
+ ): Promise<JimpexHTTPSCredentials> {
662
+ const location = onHome ? 'home' : 'app';
663
+ const pathUtils = this.get<PathUtils>('pathUtils');
664
+ const keys: Array<keyof JimpexHTTPSCredentials> = ['ca', 'cert', 'key'];
665
+ const info = await Promise.all(
666
+ keys.map(async (key) => {
667
+ const filepath = credentialsInfo[key];
668
+ if (!filepath) return undefined;
669
+ const file = await fs.readFile(pathUtils.joinFrom(location, filepath), 'utf8');
670
+ return {
671
+ key,
672
+ file,
673
+ };
674
+ }),
675
+ );
676
+
677
+ return info.reduce<JimpexHTTPSCredentials>((acc, item) => {
678
+ if (item) {
679
+ acc[item.key] = item.file;
680
+ }
681
+
682
+ return acc;
683
+ }, {});
684
+ }
685
+ /**
686
+ * Validates the configuration and chooses the server the application needs to use: If
687
+ * HTTP2 is enabled, it will use Spdy; if HTTPS is enabled but HTTP is not, it will use
688
+ * the native HTTPS server; otherwise, it will be just the Express instance.
689
+ *
690
+ * @returns {Server}
691
+ * @throws {Error} If HTTP2 is enabled but HTTPS is not.
692
+ * @throws {Error} If HTTPS is enabled but there's no `https.credentials` object.
693
+ * @throws {Error} If HTTPS is enabled and no creadentials are found.
694
+ * @access protected
695
+ * @ignore
696
+ */
697
+ protected async _createServer(): Promise<JimpexServer> {
698
+ const [http2Config = {}, httpsConfig = {}] = this.getConfig<
699
+ [JimpexHTTP2Options, JimpexHTTPSOptions]
700
+ >(['http2', 'https'], true);
701
+
702
+ if (!http2Config.enabled && !httpsConfig.enabled) {
703
+ return this._express;
704
+ }
705
+
706
+ if (http2Config.enabled && !httpsConfig.enabled) {
707
+ throw new Error('HTTP2 requires for HTTPS to be enabled');
708
+ }
709
+
710
+ if (!httpsConfig.credentials) {
711
+ throw new Error('The `credentials` object on the HTTPS settings is missing');
712
+ }
713
+
714
+ const credentials = await this._loadCredentials(
715
+ httpsConfig.credentials,
716
+ httpsConfig.credentials.onHome,
717
+ );
718
+
719
+ if (!Object.keys(credentials).length) {
720
+ throw new Error('No credentials were found for HTTPS');
721
+ }
722
+
723
+ if (http2Config.enabled) {
724
+ const serverOptions: SpdyServerOptions = {
725
+ ...credentials,
726
+ spdy: http2Config.spdy,
727
+ };
728
+
729
+ return createSpdyServer(serverOptions, this._express);
730
+ }
731
+
732
+ return createHTTPSServer(credentials, this._express);
733
+ }
734
+ }
735
+ /**
736
+ * Shorthand for `new Jimpex()`.
737
+ *
738
+ * @param args The same parameters as the {@link Jimpex} constructor.
739
+ * @returns A new instance of {@link Jimpex}.
740
+ * @group Jimpex
741
+ */
742
+ export const jimpex = (...args: ConstructorParameters<typeof Jimpex>): Jimpex =>
743
+ new Jimpex(...args);