jimpex 10.0.2 → 11.0.1

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 (346) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +7 -9
  3. package/dist/app/index.d.ts +1 -1
  4. package/dist/app/index.js +1 -22
  5. package/dist/app/index.js.map +1 -1
  6. package/dist/app/jimpex.d.ts +1 -1
  7. package/dist/app/jimpex.js +100 -131
  8. package/dist/app/jimpex.js.map +1 -1
  9. package/dist/controllers/common/config.d.ts +2 -2
  10. package/dist/controllers/common/config.js +12 -39
  11. package/dist/controllers/common/config.js.map +1 -1
  12. package/dist/controllers/common/health.d.ts +4 -4
  13. package/dist/controllers/common/health.js +20 -47
  14. package/dist/controllers/common/health.js.map +1 -1
  15. package/dist/controllers/common/index.d.ts +1 -1
  16. package/dist/controllers/common/index.js +3 -26
  17. package/dist/controllers/common/index.js.map +1 -1
  18. package/dist/controllers/common/statics.d.ts +3 -3
  19. package/dist/controllers/common/statics.js +32 -65
  20. package/dist/controllers/common/statics.js.map +1 -1
  21. package/dist/controllers/index.d.ts +1 -1
  22. package/dist/controllers/index.js +2 -24
  23. package/dist/controllers/index.js.map +1 -1
  24. package/dist/controllers/utils/gateway.d.ts +5 -5
  25. package/dist/controllers/utils/gateway.js +70 -91
  26. package/dist/controllers/utils/gateway.js.map +1 -1
  27. package/dist/controllers/utils/index.d.ts +1 -1
  28. package/dist/controllers/utils/index.js +1 -22
  29. package/dist/controllers/utils/index.js.map +1 -1
  30. package/dist/{index-C6I3NCC-.d.ts → index-BlSpNHox.d.ts} +13 -13
  31. package/dist/index.d.ts +3 -3
  32. package/dist/index.js +6 -32
  33. package/dist/index.js.map +1 -1
  34. package/dist/middlewares/common/errorHandler.d.ts +5 -5
  35. package/dist/middlewares/common/errorHandler.js +31 -56
  36. package/dist/middlewares/common/errorHandler.js.map +1 -1
  37. package/dist/middlewares/common/forceHTTPS.d.ts +1 -1
  38. package/dist/middlewares/common/forceHTTPS.js +8 -35
  39. package/dist/middlewares/common/forceHTTPS.js.map +1 -1
  40. package/dist/middlewares/common/hsts.d.ts +1 -1
  41. package/dist/middlewares/common/hsts.js +12 -39
  42. package/dist/middlewares/common/hsts.js.map +1 -1
  43. package/dist/middlewares/common/index.d.ts +3 -3
  44. package/dist/middlewares/common/index.js +3 -26
  45. package/dist/middlewares/common/index.js.map +1 -1
  46. package/dist/middlewares/html/fastHTML.d.ts +4 -4
  47. package/dist/middlewares/html/fastHTML.js +43 -66
  48. package/dist/middlewares/html/fastHTML.js.map +1 -1
  49. package/dist/middlewares/html/index.d.ts +2 -2
  50. package/dist/middlewares/html/index.js +2 -24
  51. package/dist/middlewares/html/index.js.map +1 -1
  52. package/dist/middlewares/html/showHTML.d.ts +3 -3
  53. package/dist/middlewares/html/showHTML.js +25 -52
  54. package/dist/middlewares/html/showHTML.js.map +1 -1
  55. package/dist/middlewares/index.d.ts +4 -4
  56. package/dist/middlewares/index.js +3 -26
  57. package/dist/middlewares/index.js.map +1 -1
  58. package/dist/middlewares/utils/index.d.ts +3 -3
  59. package/dist/middlewares/utils/index.js +1 -22
  60. package/dist/middlewares/utils/index.js.map +1 -1
  61. package/dist/middlewares/utils/versionValidator.d.ts +5 -5
  62. package/dist/middlewares/utils/versionValidator.js +24 -51
  63. package/dist/middlewares/utils/versionValidator.js.map +1 -1
  64. package/dist/services/common/appError.d.ts +2 -2
  65. package/dist/services/common/appError.js +18 -46
  66. package/dist/services/common/appError.js.map +1 -1
  67. package/dist/services/common/httpError.d.ts +2 -2
  68. package/dist/services/common/httpError.js +7 -33
  69. package/dist/services/common/httpError.js.map +1 -1
  70. package/dist/services/common/index.d.ts +1 -1
  71. package/dist/services/common/index.js +14 -42
  72. package/dist/services/common/index.js.map +1 -1
  73. package/dist/services/common/sendFile.d.ts +1 -1
  74. package/dist/services/common/sendFile.js +4 -29
  75. package/dist/services/common/sendFile.js.map +1 -1
  76. package/dist/services/frontend/frontendFs.d.ts +2 -2
  77. package/dist/services/frontend/frontendFs.js +12 -49
  78. package/dist/services/frontend/frontendFs.js.map +1 -1
  79. package/dist/services/frontend/index.d.ts +2 -2
  80. package/dist/services/frontend/index.js +8 -34
  81. package/dist/services/frontend/index.js.map +1 -1
  82. package/dist/services/html/htmlGenerator.d.ts +5 -5
  83. package/dist/services/html/htmlGenerator.js +46 -75
  84. package/dist/services/html/htmlGenerator.js.map +1 -1
  85. package/dist/services/html/index.d.ts +2 -2
  86. package/dist/services/html/index.js +8 -34
  87. package/dist/services/html/index.js.map +1 -1
  88. package/dist/services/http/apiClient.d.ts +1 -1
  89. package/dist/services/http/apiClient.js +23 -48
  90. package/dist/services/http/apiClient.js.map +1 -1
  91. package/dist/services/http/http.d.ts +5 -5
  92. package/dist/services/http/http.js +23 -60
  93. package/dist/services/http/http.js.map +1 -1
  94. package/dist/services/http/index.d.ts +2 -2
  95. package/dist/services/http/index.js +14 -42
  96. package/dist/services/http/index.js.map +1 -1
  97. package/dist/services/http/responsesBuilder.d.ts +4 -4
  98. package/dist/services/http/responsesBuilder.js +13 -40
  99. package/dist/services/http/responsesBuilder.js.map +1 -1
  100. package/dist/services/index.d.ts +3 -3
  101. package/dist/services/index.js +5 -30
  102. package/dist/services/index.js.map +1 -1
  103. package/dist/services/utils/ensureBearerToken.d.ts +2 -2
  104. package/dist/services/utils/ensureBearerToken.js +15 -42
  105. package/dist/services/utils/ensureBearerToken.js.map +1 -1
  106. package/dist/services/utils/index.d.ts +1 -1
  107. package/dist/services/utils/index.js +8 -34
  108. package/dist/services/utils/index.js.map +1 -1
  109. package/dist/types/events.d.ts +1 -1
  110. package/dist/types/events.js +0 -16
  111. package/dist/types/events.js.map +1 -1
  112. package/dist/types/express.js +0 -16
  113. package/dist/types/express.js.map +1 -1
  114. package/dist/types/http.js +0 -16
  115. package/dist/types/http.js.map +1 -1
  116. package/dist/types/index.d.ts +1 -1
  117. package/dist/types/index.js +6 -32
  118. package/dist/types/index.js.map +1 -1
  119. package/dist/types/options.d.ts +1 -1
  120. package/dist/types/options.js +0 -16
  121. package/dist/types/options.js.map +1 -1
  122. package/dist/types/utils.js +0 -16
  123. package/dist/types/utils.js.map +1 -1
  124. package/dist/types/wootils.js +0 -16
  125. package/dist/types/wootils.js.map +1 -1
  126. package/dist/utils/fns/index.js +4 -28
  127. package/dist/utils/fns/index.js.map +1 -1
  128. package/dist/utils/fns/others.js +2 -26
  129. package/dist/utils/fns/others.js.map +1 -1
  130. package/dist/utils/fns/routes.js +4 -31
  131. package/dist/utils/fns/routes.js.map +1 -1
  132. package/dist/utils/fns/statuses.js +3 -37
  133. package/dist/utils/fns/statuses.js.map +1 -1
  134. package/dist/utils/fns/text.js +2 -26
  135. package/dist/utils/fns/text.js.map +1 -1
  136. package/dist/utils/index.d.ts +1 -1
  137. package/dist/utils/index.js +2 -24
  138. package/dist/utils/index.js.map +1 -1
  139. package/dist/utils/wrappers.d.ts +1 -1
  140. package/dist/utils/wrappers.js +20 -48
  141. package/dist/utils/wrappers.js.map +1 -1
  142. package/eslint.config.js +19 -0
  143. package/examples/basic/app.ts +4 -4
  144. package/examples/basic/controller.ts +2 -2
  145. package/examples/basic/index.ts +4 -4
  146. package/examples/basic/middleware.ts +2 -2
  147. package/examples/basic/service.ts +1 -1
  148. package/package.json +61 -49
  149. package/pnpm-workspace.yaml +4 -0
  150. package/src/app/index.ts +1 -1
  151. package/src/app/jimpex.ts +23 -20
  152. package/src/controllers/common/config.ts +4 -4
  153. package/src/controllers/common/health.ts +9 -5
  154. package/src/controllers/common/index.ts +3 -3
  155. package/src/controllers/common/statics.ts +12 -7
  156. package/src/controllers/index.ts +2 -2
  157. package/src/controllers/utils/gateway.ts +8 -8
  158. package/src/controllers/utils/index.ts +1 -1
  159. package/src/index.ts +6 -6
  160. package/src/middlewares/common/errorHandler.ts +9 -5
  161. package/src/middlewares/common/forceHTTPS.ts +2 -2
  162. package/src/middlewares/common/hsts.ts +2 -2
  163. package/src/middlewares/common/index.ts +3 -3
  164. package/src/middlewares/html/fastHTML.ts +14 -5
  165. package/src/middlewares/html/index.ts +2 -2
  166. package/src/middlewares/html/showHTML.ts +8 -4
  167. package/src/middlewares/index.ts +3 -3
  168. package/src/middlewares/utils/index.ts +1 -1
  169. package/src/middlewares/utils/versionValidator.ts +6 -6
  170. package/src/services/common/appError.ts +1 -1
  171. package/src/services/common/httpError.ts +2 -2
  172. package/src/services/common/index.ts +7 -7
  173. package/src/services/common/sendFile.ts +2 -2
  174. package/src/services/frontend/frontendFs.ts +3 -3
  175. package/src/services/frontend/index.ts +3 -3
  176. package/src/services/html/htmlGenerator.ts +11 -13
  177. package/src/services/html/index.ts +3 -3
  178. package/src/services/http/apiClient.ts +3 -3
  179. package/src/services/http/http.ts +5 -5
  180. package/src/services/http/index.ts +7 -7
  181. package/src/services/http/responsesBuilder.ts +5 -5
  182. package/src/services/index.ts +5 -5
  183. package/src/services/utils/ensureBearerToken.ts +4 -4
  184. package/src/services/utils/index.ts +3 -3
  185. package/src/types/events.ts +8 -8
  186. package/src/types/http.ts +1 -1
  187. package/src/types/index.ts +6 -6
  188. package/src/types/options.ts +2 -2
  189. package/src/types/utils.ts +4 -4
  190. package/src/utils/fns/index.ts +4 -4
  191. package/src/utils/fns/routes.ts +1 -1
  192. package/src/utils/index.ts +2 -2
  193. package/src/utils/wrappers.ts +6 -6
  194. package/tsconfig.json +9 -4
  195. package/tsup.config.ts +1 -2
  196. package/vitest.config.ts +24 -0
  197. package/dist/app/index.d.mts +0 -14
  198. package/dist/app/jimpex.d.mts +0 -14
  199. package/dist/controllers/common/config.d.mts +0 -79
  200. package/dist/controllers/common/health.d.mts +0 -83
  201. package/dist/controllers/common/index.d.mts +0 -22
  202. package/dist/controllers/common/statics.d.mts +0 -223
  203. package/dist/controllers/index.d.mts +0 -25
  204. package/dist/controllers/utils/gateway.d.mts +0 -725
  205. package/dist/controllers/utils/index.d.mts +0 -17
  206. package/dist/esm/app/index.js +0 -2
  207. package/dist/esm/app/index.js.map +0 -1
  208. package/dist/esm/app/jimpex.js +0 -640
  209. package/dist/esm/app/jimpex.js.map +0 -1
  210. package/dist/esm/chunk-V6TY7KAL.js +0 -8
  211. package/dist/esm/chunk-V6TY7KAL.js.map +0 -1
  212. package/dist/esm/controllers/common/config.js +0 -80
  213. package/dist/esm/controllers/common/config.js.map +0 -1
  214. package/dist/esm/controllers/common/health.js +0 -88
  215. package/dist/esm/controllers/common/health.js.map +0 -1
  216. package/dist/esm/controllers/common/index.js +0 -4
  217. package/dist/esm/controllers/common/index.js.map +0 -1
  218. package/dist/esm/controllers/common/statics.js +0 -226
  219. package/dist/esm/controllers/common/statics.js.map +0 -1
  220. package/dist/esm/controllers/index.js +0 -3
  221. package/dist/esm/controllers/index.js.map +0 -1
  222. package/dist/esm/controllers/utils/gateway.js +0 -559
  223. package/dist/esm/controllers/utils/gateway.js.map +0 -1
  224. package/dist/esm/controllers/utils/index.js +0 -2
  225. package/dist/esm/controllers/utils/index.js.map +0 -1
  226. package/dist/esm/index.js +0 -7
  227. package/dist/esm/index.js.map +0 -1
  228. package/dist/esm/middlewares/common/errorHandler.js +0 -116
  229. package/dist/esm/middlewares/common/errorHandler.js.map +0 -1
  230. package/dist/esm/middlewares/common/forceHTTPS.js +0 -52
  231. package/dist/esm/middlewares/common/forceHTTPS.js.map +0 -1
  232. package/dist/esm/middlewares/common/hsts.js +0 -74
  233. package/dist/esm/middlewares/common/hsts.js.map +0 -1
  234. package/dist/esm/middlewares/common/index.js +0 -4
  235. package/dist/esm/middlewares/common/index.js.map +0 -1
  236. package/dist/esm/middlewares/html/fastHTML.js +0 -157
  237. package/dist/esm/middlewares/html/fastHTML.js.map +0 -1
  238. package/dist/esm/middlewares/html/index.js +0 -3
  239. package/dist/esm/middlewares/html/index.js.map +0 -1
  240. package/dist/esm/middlewares/html/showHTML.js +0 -100
  241. package/dist/esm/middlewares/html/showHTML.js.map +0 -1
  242. package/dist/esm/middlewares/index.js +0 -4
  243. package/dist/esm/middlewares/index.js.map +0 -1
  244. package/dist/esm/middlewares/utils/index.js +0 -2
  245. package/dist/esm/middlewares/utils/index.js.map +0 -1
  246. package/dist/esm/middlewares/utils/versionValidator.js +0 -135
  247. package/dist/esm/middlewares/utils/versionValidator.js.map +0 -1
  248. package/dist/esm/services/common/appError.js +0 -98
  249. package/dist/esm/services/common/appError.js.map +0 -1
  250. package/dist/esm/services/common/httpError.js +0 -28
  251. package/dist/esm/services/common/httpError.js.map +0 -1
  252. package/dist/esm/services/common/index.js +0 -17
  253. package/dist/esm/services/common/index.js.map +0 -1
  254. package/dist/esm/services/common/sendFile.js +0 -27
  255. package/dist/esm/services/common/sendFile.js.map +0 -1
  256. package/dist/esm/services/frontend/frontendFs.js +0 -66
  257. package/dist/esm/services/frontend/frontendFs.js.map +0 -1
  258. package/dist/esm/services/frontend/index.js +0 -11
  259. package/dist/esm/services/frontend/index.js.map +0 -1
  260. package/dist/esm/services/html/htmlGenerator.js +0 -192
  261. package/dist/esm/services/html/htmlGenerator.js.map +0 -1
  262. package/dist/esm/services/html/index.js +0 -11
  263. package/dist/esm/services/html/index.js.map +0 -1
  264. package/dist/esm/services/http/apiClient.js +0 -94
  265. package/dist/esm/services/http/apiClient.js.map +0 -1
  266. package/dist/esm/services/http/http.js +0 -180
  267. package/dist/esm/services/http/http.js.map +0 -1
  268. package/dist/esm/services/http/index.js +0 -17
  269. package/dist/esm/services/http/index.js.map +0 -1
  270. package/dist/esm/services/http/responsesBuilder.js +0 -152
  271. package/dist/esm/services/http/responsesBuilder.js.map +0 -1
  272. package/dist/esm/services/index.js +0 -6
  273. package/dist/esm/services/index.js.map +0 -1
  274. package/dist/esm/services/utils/ensureBearerToken.js +0 -94
  275. package/dist/esm/services/utils/ensureBearerToken.js.map +0 -1
  276. package/dist/esm/services/utils/index.js +0 -11
  277. package/dist/esm/services/utils/index.js.map +0 -1
  278. package/dist/esm/types/events.js +0 -1
  279. package/dist/esm/types/events.js.map +0 -1
  280. package/dist/esm/types/express.js +0 -1
  281. package/dist/esm/types/express.js.map +0 -1
  282. package/dist/esm/types/http.js +0 -1
  283. package/dist/esm/types/http.js.map +0 -1
  284. package/dist/esm/types/index.js +0 -7
  285. package/dist/esm/types/index.js.map +0 -1
  286. package/dist/esm/types/options.js +0 -1
  287. package/dist/esm/types/options.js.map +0 -1
  288. package/dist/esm/types/utils.js +0 -1
  289. package/dist/esm/types/utils.js.map +0 -1
  290. package/dist/esm/types/wootils.js +0 -1
  291. package/dist/esm/types/wootils.js.map +0 -1
  292. package/dist/esm/utils/fns/index.js +0 -5
  293. package/dist/esm/utils/fns/index.js.map +0 -1
  294. package/dist/esm/utils/fns/others.js +0 -6
  295. package/dist/esm/utils/fns/others.js.map +0 -1
  296. package/dist/esm/utils/fns/routes.js +0 -25
  297. package/dist/esm/utils/fns/routes.js.map +0 -1
  298. package/dist/esm/utils/fns/statuses.js +0 -6
  299. package/dist/esm/utils/fns/statuses.js.map +0 -1
  300. package/dist/esm/utils/fns/text.js +0 -6
  301. package/dist/esm/utils/fns/text.js.map +0 -1
  302. package/dist/esm/utils/index.js +0 -3
  303. package/dist/esm/utils/index.js.map +0 -1
  304. package/dist/esm/utils/wrappers.js +0 -41
  305. package/dist/esm/utils/wrappers.js.map +0 -1
  306. package/dist/index-Bwf7JHu9.d.mts +0 -1287
  307. package/dist/index.d.mts +0 -47
  308. package/dist/middlewares/common/errorHandler.d.mts +0 -132
  309. package/dist/middlewares/common/forceHTTPS.d.mts +0 -69
  310. package/dist/middlewares/common/hsts.d.mts +0 -110
  311. package/dist/middlewares/common/index.d.mts +0 -22
  312. package/dist/middlewares/html/fastHTML.d.mts +0 -180
  313. package/dist/middlewares/html/index.d.mts +0 -21
  314. package/dist/middlewares/html/showHTML.d.mts +0 -127
  315. package/dist/middlewares/index.d.mts +0 -30
  316. package/dist/middlewares/utils/index.d.mts +0 -20
  317. package/dist/middlewares/utils/versionValidator.d.mts +0 -215
  318. package/dist/services/common/appError.d.mts +0 -139
  319. package/dist/services/common/httpError.d.mts +0 -80
  320. package/dist/services/common/index.d.mts +0 -47
  321. package/dist/services/common/sendFile.d.mts +0 -102
  322. package/dist/services/frontend/frontendFs.d.mts +0 -96
  323. package/dist/services/frontend/index.d.mts +0 -40
  324. package/dist/services/html/htmlGenerator.d.mts +0 -237
  325. package/dist/services/html/index.d.mts +0 -43
  326. package/dist/services/http/apiClient.d.mts +0 -170
  327. package/dist/services/http/http.d.mts +0 -182
  328. package/dist/services/http/index.d.mts +0 -51
  329. package/dist/services/http/responsesBuilder.d.mts +0 -179
  330. package/dist/services/index.d.mts +0 -33
  331. package/dist/services/utils/ensureBearerToken.d.mts +0 -158
  332. package/dist/services/utils/index.d.mts +0 -44
  333. package/dist/types/events.d.mts +0 -14
  334. package/dist/types/express.d.mts +0 -10
  335. package/dist/types/http.d.mts +0 -82
  336. package/dist/types/index.d.mts +0 -14
  337. package/dist/types/options.d.mts +0 -14
  338. package/dist/types/utils.d.mts +0 -48
  339. package/dist/types/wootils.d.mts +0 -4
  340. package/dist/utils/fns/index.d.mts +0 -5
  341. package/dist/utils/fns/others.d.mts +0 -17
  342. package/dist/utils/fns/routes.d.mts +0 -39
  343. package/dist/utils/fns/statuses.d.mts +0 -45
  344. package/dist/utils/fns/text.d.mts +0 -9
  345. package/dist/utils/index.d.mts +0 -19
  346. package/dist/utils/wrappers.d.mts +0 -14
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/common/errorHandler.ts"],"sourcesContent":["import { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { middlewareCreator, type Statuses } from '../../utils';\nimport type { DeepPartial, Logger, ExpressErrorHandler } from '../../types';\nimport { AppError, type HTTPErrorClass, type ResponsesBuilder } from '../../services';\n/**\n * The options for the responses the middleware will create.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerResponseOptions = {\n /**\n * The message to show in case `showErrors` is set to `false`.\n *\n * @default 'Oops! Something went wrong, please try again'\n * @prettierignore\n */\n message: string;\n /**\n * The default status code for the responses.\n *\n * @default 500\n */\n status: number;\n};\n/**\n * The customization options for the middleware.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerOptions = {\n /**\n * If `false`, unknown errors will show a generic message instead of real message. And\n * if `true`, it will not only show all kind of errors but it will also show the error\n * stack.\n *\n * By \"uknown errors\", it means that are not `AppError` nor `HTTPError`.\n */\n showErrors: boolean;\n /**\n * The options for the default response the middleware will create.\n */\n response: ErrorHandlerResponseOptions;\n};\n/**\n * A partial version of the {@link ErrorHandlerOptions}, to be used in the constructor and\n * the middleware creator.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerPartialOptions = DeepPartial<ErrorHandlerOptions>;\n/**\n * The options to construct a {@link ErrorHandler}.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerConstructorOptions = ErrorHandlerPartialOptions & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n logger: Logger;\n responsesBuilder: ResponsesBuilder;\n statuses: Statuses;\n HTTPError: HTTPErrorClass;\n };\n};\n/**\n * Creates a middleware that handles errors and generates the responses.\n *\n * @group Middleware Classes\n * @group Middlewares/ErrorHandler\n * @prettierignore\n */\nexport class ErrorHandler {\n /**\n * The service that will log the messages in the console.\n */\n protected readonly _logger: Logger;\n /**\n * The service to generate the responses.\n */\n protected readonly _responsesBuilder: ResponsesBuilder;\n /**\n * The uility service to get HTTP status codes.\n */\n protected readonly _statuses: Statuses;\n /**\n * The Error class used by the \"known errors\".\n */\n protected readonly _HTTPError: HTTPErrorClass;\n /**\n * The customization options.\n */\n protected readonly _options: ErrorHandlerOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor({\n inject: { logger, responsesBuilder, statuses, HTTPError },\n ...options\n }: ErrorHandlerConstructorOptions) {\n this._logger = logger;\n this._responsesBuilder = responsesBuilder;\n this._statuses = statuses;\n this._HTTPError = HTTPError;\n this._options = deepAssignWithOverwrite(\n {\n showErrors: false,\n response: {\n message: 'Unexpected error',\n status: this._statuses('internal server error'),\n },\n },\n options,\n );\n }\n /**\n * Generates the middleware that handles the errors.\n */\n getMiddleware(): ExpressErrorHandler {\n return (err, _, res, next) => {\n // If there wasn't any error, continue the execution.\n if (!err) {\n next();\n return;\n }\n\n const { response, showErrors } = this._options;\n\n // Define the base status and response.\n let { status } = response;\n let data: {\n error: boolean;\n message: string;\n stack?: string[];\n } & Record<string, unknown> = {\n error: true,\n message: response.message,\n };\n\n const knownError = err instanceof AppError;\n // If it's a \"known error\" or the `showErrors` flag is set to `true`...\n if (showErrors || knownError) {\n // Get the real message.\n data.message = err.message;\n // If it's a \"known error\"...\n if (knownError) {\n // Try to extract information for the response.\n data = {\n ...data,\n ...err.getResponse(),\n };\n status = err.status || (this._statuses('bad request') as number);\n }\n /**\n * If the flag is set to `true`, and it's a \"valid error\", try to extract the\n * stack, format it, and include it in the response.\n */\n if (showErrors && err instanceof Error && err.stack) {\n const stack = err.stack.split('\\n').map((line) => line.trim());\n data.stack = stack;\n stack.splice(0, 1);\n this._logger.error(`ERROR: ${err.message}`);\n this._logger.info(stack);\n }\n }\n\n this._responsesBuilder.json({\n res,\n data,\n status,\n });\n };\n }\n /**\n * The handler customization options.\n */\n get options(): Readonly<ErrorHandlerOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n}\n/**\n * Creates the middleware that handles errors.\n *\n * @group Middlewares\n * @group Middlewares/ErrorHandler\n */\nexport const errorHandlerMiddleware = middlewareCreator(\n (options: ErrorHandlerPartialOptions = {}) =>\n (app) => {\n const showErrors = app.getConfig<boolean | undefined>('debug.showErrors') === true;\n return new ErrorHandler({\n inject: {\n logger: app.get('logger'),\n responsesBuilder: app.get('responsesBuilder'),\n statuses: app.get('statuses'),\n HTTPError: app.get('HTTPError'),\n },\n showErrors,\n ...options,\n }).getMiddleware();\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAwC;AACxC,mBAAiD;AAEjD,sBAAqE;AAsE9D,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA,EAwBxB,YAAY;AAAA,IACV,QAAQ,EAAE,QAAQ,kBAAkB,UAAU,UAAU;AAAA,IACxD,GAAG;AAAA,EACL,GAAmC;AAvBnC;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAQjB,SAAK,UAAU;AACf,SAAK,oBAAoB;AACzB,SAAK,YAAY;AACjB,SAAK,aAAa;AAClB,SAAK,eAAW;AAAA,MACd;AAAA,QACE,YAAY;AAAA,QACZ,UAAU;AAAA,UACR,SAAS;AAAA,UACT,QAAQ,KAAK,UAAU,uBAAuB;AAAA,QAChD;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAqC;AACnC,WAAO,CAAC,KAAK,GAAG,KAAK,SAAS;AAE5B,UAAI,CAAC,KAAK;AACR,aAAK;AACL;AAAA,MACF;AAEA,YAAM,EAAE,UAAU,WAAW,IAAI,KAAK;AAGtC,UAAI,EAAE,OAAO,IAAI;AACjB,UAAI,OAI0B;AAAA,QAC5B,OAAO;AAAA,QACP,SAAS,SAAS;AAAA,MACpB;AAEA,YAAM,aAAa,eAAe;AAElC,UAAI,cAAc,YAAY;AAE5B,aAAK,UAAU,IAAI;AAEnB,YAAI,YAAY;AAEd,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,GAAG,IAAI,YAAY;AAAA,UACrB;AACA,mBAAS,IAAI,UAAW,KAAK,UAAU,aAAa;AAAA,QACtD;AAKA,YAAI,cAAc,eAAe,SAAS,IAAI,OAAO;AACnD,gBAAM,QAAQ,IAAI,MAAM,MAAM,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC;AAC7D,eAAK,QAAQ;AACb,gBAAM,OAAO,GAAG,CAAC;AACjB,eAAK,QAAQ,MAAM,UAAU,IAAI,OAAO,EAAE;AAC1C,eAAK,QAAQ,KAAK,KAAK;AAAA,QACzB;AAAA,MACF;AAEA,WAAK,kBAAkB,KAAK;AAAA,QAC1B;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAyC;AAC3C,eAAO,4CAAwB,CAAC,GAAG,KAAK,QAAQ;AAAA,EAClD;AACF;AAOO,MAAM,6BAAyB;AAAA,EACpC,CAAC,UAAsC,CAAC,MACtC,CAAC,QAAQ;AACP,UAAM,aAAa,IAAI,UAA+B,kBAAkB,MAAM;AAC9E,WAAO,IAAI,aAAa;AAAA,MACtB,QAAQ;AAAA,QACN,QAAQ,IAAI,IAAI,QAAQ;AAAA,QACxB,kBAAkB,IAAI,IAAI,kBAAkB;AAAA,QAC5C,UAAU,IAAI,IAAI,UAAU;AAAA,QAC5B,WAAW,IAAI,IAAI,WAAW;AAAA,MAChC;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,CAAC,EAAE,cAAc;AAAA,EACnB;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/middlewares/common/errorHandler.ts"],"sourcesContent":["import { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { middlewareCreator, type Statuses } from '../../utils/index.js';\nimport type { DeepPartial, Logger, ExpressErrorHandler } from '../../types/index.js';\nimport {\n AppError,\n type HTTPErrorClass,\n type ResponsesBuilder,\n} from '../../services/index.js';\n/**\n * The options for the responses the middleware will create.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerResponseOptions = {\n /**\n * The message to show in case `showErrors` is set to `false`.\n *\n * @default 'Oops! Something went wrong, please try again'\n * @prettierignore\n */\n message: string;\n /**\n * The default status code for the responses.\n *\n * @default 500\n */\n status: number;\n};\n/**\n * The customization options for the middleware.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerOptions = {\n /**\n * If `false`, unknown errors will show a generic message instead of real message. And\n * if `true`, it will not only show all kind of errors but it will also show the error\n * stack.\n *\n * By \"unknown errors\", it means that are not `AppError` nor `HTTPError`.\n */\n showErrors: boolean;\n /**\n * The options for the default response the middleware will create.\n */\n response: ErrorHandlerResponseOptions;\n};\n/**\n * A partial version of the {@link ErrorHandlerOptions}, to be used in the constructor and\n * the middleware creator.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerPartialOptions = DeepPartial<ErrorHandlerOptions>;\n/**\n * The options to construct a {@link ErrorHandler}.\n *\n * @group Middlewares/ErrorHandler\n */\nexport type ErrorHandlerConstructorOptions = ErrorHandlerPartialOptions & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n logger: Logger;\n responsesBuilder: ResponsesBuilder;\n statuses: Statuses;\n HTTPError: HTTPErrorClass;\n };\n};\n/**\n * Creates a middleware that handles errors and generates the responses.\n *\n * @group Middleware Classes\n * @group Middlewares/ErrorHandler\n * @prettierignore\n */\nexport class ErrorHandler {\n /**\n * The service that will log the messages in the console.\n */\n protected readonly _logger: Logger;\n /**\n * The service to generate the responses.\n */\n protected readonly _responsesBuilder: ResponsesBuilder;\n /**\n * The utility service to get HTTP status codes.\n */\n protected readonly _statuses: Statuses;\n /**\n * The Error class used by the \"known errors\".\n */\n protected readonly _HTTPError: HTTPErrorClass;\n /**\n * The customization options.\n */\n protected readonly _options: ErrorHandlerOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor({\n inject: { logger, responsesBuilder, statuses, HTTPError },\n ...options\n }: ErrorHandlerConstructorOptions) {\n this._logger = logger;\n this._responsesBuilder = responsesBuilder;\n this._statuses = statuses;\n this._HTTPError = HTTPError;\n this._options = deepAssignWithOverwrite(\n {\n showErrors: false,\n response: {\n message: 'Unexpected error',\n status: this._statuses('internal server error'),\n },\n },\n options,\n );\n }\n /**\n * Generates the middleware that handles the errors.\n */\n getMiddleware(): ExpressErrorHandler {\n return (err, _, res, next) => {\n // If there wasn't any error, continue the execution.\n if (!err) {\n next();\n return;\n }\n\n const { response, showErrors } = this._options;\n\n // Define the base status and response.\n let { status } = response;\n let data: {\n error: boolean;\n message: string;\n stack?: string[];\n } & Record<string, unknown> = {\n error: true,\n message: response.message,\n };\n\n const knownError = err instanceof AppError;\n // If it's a \"known error\" or the `showErrors` flag is set to `true`...\n if (showErrors || knownError) {\n // Get the real message.\n data.message = err.message;\n // If it's a \"known error\"...\n if (knownError) {\n // Try to extract information for the response.\n data = {\n ...data,\n ...err.getResponse(),\n };\n status = err.status || (this._statuses('bad request') as number);\n }\n /**\n * If the flag is set to `true`, and it's a \"valid error\", try to extract the\n * stack, format it, and include it in the response.\n */\n if (showErrors && err instanceof Error && err.stack) {\n const stack = err.stack.split('\\n').map((line) => line.trim());\n data.stack = stack;\n stack.splice(0, 1);\n this._logger.error(`ERROR: ${err.message}`);\n this._logger.info(stack);\n }\n }\n\n this._responsesBuilder.json({\n res,\n data,\n status,\n });\n };\n }\n /**\n * The handler customization options.\n */\n get options(): Readonly<ErrorHandlerOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n}\n/**\n * Creates the middleware that handles errors.\n *\n * @group Middlewares\n * @group Middlewares/ErrorHandler\n */\nexport const errorHandlerMiddleware = middlewareCreator(\n (options: ErrorHandlerPartialOptions = {}) =>\n (app) => {\n const showErrors = app.getConfig<boolean | undefined>('debug.showErrors') === true;\n return new ErrorHandler({\n inject: {\n logger: app.get('logger'),\n responsesBuilder: app.get('responsesBuilder'),\n statuses: app.get('statuses'),\n HTTPError: app.get('HTTPError'),\n },\n showErrors,\n ...options,\n }).getMiddleware();\n },\n);\n"],"mappings":"AAAA,SAAS,+BAA+B;AACxC,SAAS,yBAAwC;AAEjD;AAAA,EACE;AAAA,OAGK;AAsEA,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA,EAIL;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA,EAInB,YAAY;AAAA,IACV,QAAQ,EAAE,QAAQ,kBAAkB,UAAU,UAAU;AAAA,IACxD,GAAG;AAAA,EACL,GAAmC;AACjC,SAAK,UAAU;AACf,SAAK,oBAAoB;AACzB,SAAK,YAAY;AACjB,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,MACd;AAAA,QACE,YAAY;AAAA,QACZ,UAAU;AAAA,UACR,SAAS;AAAA,UACT,QAAQ,KAAK,UAAU,uBAAuB;AAAA,QAChD;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAqC;AACnC,WAAO,CAAC,KAAK,GAAG,KAAK,SAAS;AAE5B,UAAI,CAAC,KAAK;AACR,aAAK;AACL;AAAA,MACF;AAEA,YAAM,EAAE,UAAU,WAAW,IAAI,KAAK;AAGtC,UAAI,EAAE,OAAO,IAAI;AACjB,UAAI,OAI0B;AAAA,QAC5B,OAAO;AAAA,QACP,SAAS,SAAS;AAAA,MACpB;AAEA,YAAM,aAAa,eAAe;AAElC,UAAI,cAAc,YAAY;AAE5B,aAAK,UAAU,IAAI;AAEnB,YAAI,YAAY;AAEd,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,GAAG,IAAI,YAAY;AAAA,UACrB;AACA,mBAAS,IAAI,UAAW,KAAK,UAAU,aAAa;AAAA,QACtD;AAKA,YAAI,cAAc,eAAe,SAAS,IAAI,OAAO;AACnD,gBAAM,QAAQ,IAAI,MAAM,MAAM,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC;AAC7D,eAAK,QAAQ;AACb,gBAAM,OAAO,GAAG,CAAC;AACjB,eAAK,QAAQ,MAAM,UAAU,IAAI,OAAO,EAAE;AAC1C,eAAK,QAAQ,KAAK,KAAK;AAAA,QACzB;AAAA,MACF;AAEA,WAAK,kBAAkB,KAAK;AAAA,QAC1B;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAyC;AAC3C,WAAO,wBAAwB,CAAC,GAAG,KAAK,QAAQ;AAAA,EAClD;AACF;AAOO,MAAM,yBAAyB;AAAA,EACpC,CAAC,UAAsC,CAAC,MACtC,CAAC,QAAQ;AACP,UAAM,aAAa,IAAI,UAA+B,kBAAkB,MAAM;AAC9E,WAAO,IAAI,aAAa;AAAA,MACtB,QAAQ;AAAA,QACN,QAAQ,IAAI,IAAI,QAAQ;AAAA,QACxB,kBAAkB,IAAI,IAAI,kBAAkB;AAAA,QAC5C,UAAU,IAAI,IAAI,UAAU;AAAA,QAC5B,WAAW,IAAI,IAAI,WAAW;AAAA,MAChC;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,CAAC,EAAE,cAAc;AAAA,EACnB;AACJ;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import * as _homer0_jimple from '@homer0/jimple';
2
- import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-C6I3NCC-.js';
2
+ import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-BlSpNHox.js';
3
3
  import { ExpressMiddleware } from '../../types/express.js';
4
4
  import '../../types/http.js';
5
5
  import 'https';
@@ -1,39 +1,13 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
- var forceHTTPS_exports = {};
22
- __export(forceHTTPS_exports, {
23
- ForceHTTPS: () => ForceHTTPS,
24
- forceHTTPSMiddleware: () => forceHTTPSMiddleware
25
- });
26
- module.exports = __toCommonJS(forceHTTPS_exports);
27
- var import_utils = require("../../utils");
1
+ import { middlewareCreator } from "../../utils/index.js";
28
2
  class ForceHTTPS {
3
+ /**
4
+ * The customization options.
5
+ */
6
+ _options;
29
7
  /**
30
8
  * @param options The options to construct the class.
31
9
  */
32
10
  constructor(options = {}) {
33
- /**
34
- * The customization options.
35
- */
36
- __publicField(this, "_options");
37
11
  this._options = {
38
12
  ignoredRoutes: [/^\/service\//],
39
13
  ...options
@@ -61,16 +35,15 @@ class ForceHTTPS {
61
35
  return { ...this._options };
62
36
  }
63
37
  }
64
- const forceHTTPSMiddleware = (0, import_utils.middlewareCreator)(
38
+ const forceHTTPSMiddleware = middlewareCreator(
65
39
  (options = {}) => (app) => {
66
40
  const enabled = app.getConfig("forceHTTPS");
67
41
  if (!enabled) return void 0;
68
42
  return new ForceHTTPS(options).getMiddleware();
69
43
  }
70
44
  );
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
45
+ export {
73
46
  ForceHTTPS,
74
47
  forceHTTPSMiddleware
75
- });
48
+ };
76
49
  //# sourceMappingURL=forceHTTPS.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/common/forceHTTPS.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils';\nimport { ExpressMiddleware } from '../../types';\n/**\n * The customization options for the middleware.\n *\n * @group Middlewares/ForceHTTPS\n */\nexport type ForceHTTPSOptions = {\n /**\n * A list of regular expressions to match routes that should be ignored.\n *\n * @default [/^\\/service\\//]\n */\n ignoredRoutes: RegExp[];\n};\n/**\n * A partial version of the {@link ForceHTTPSOptions}, to be used in the constructor and\n * the middleware creator.\n *\n * @group Middlewares/ForceHTTPS\n */\nexport type ForceHTTPSPartialOptions = Partial<ForceHTTPSOptions>;\n/**\n * Creates a middleware that forces all the traffic to be through HTTPS.\n *\n * @group Middleware Classes\n * @group Middlewares/ForceHTTPS\n * @prettierignore\n */\nexport class ForceHTTPS {\n /**\n * The customization options.\n */\n protected readonly _options: ForceHTTPSOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor(options: ForceHTTPSPartialOptions = {}) {\n this._options = {\n ignoredRoutes: [/^\\/service\\//],\n ...options,\n };\n }\n /**\n * Generates the middleware that redirects the traffic.\n */\n getMiddleware(): ExpressMiddleware {\n return (req, res, next) => {\n if (\n !req.secure &&\n req.get('X-Forwarded-Proto') !== 'https' &&\n !this._options.ignoredRoutes.some((expression) =>\n expression.test(req.originalUrl),\n )\n ) {\n const host = req.get('Host');\n res.redirect(`https://${host}${req.url}`);\n } else {\n next();\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<ForceHTTPSOptions> {\n return { ...this._options };\n }\n}\n/**\n * Creates the middleware that redirects the traffic to HTTPS.\n *\n * @group Middlewares\n * @group Middlewares/ForceHTTPS\n */\nexport const forceHTTPSMiddleware = middlewareCreator(\n (options: ForceHTTPSPartialOptions = {}) =>\n (app) => {\n const enabled = app.getConfig<boolean | undefined>('forceHTTPS');\n if (!enabled) return undefined;\n return new ForceHTTPS(options).getMiddleware();\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AA6B3B,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA,EAQtB,YAAY,UAAoC,CAAC,GAAG;AAJpD;AAAA;AAAA;AAAA,wBAAmB;AAKjB,SAAK,WAAW;AAAA,MACd,eAAe,CAAC,cAAc;AAAA,MAC9B,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAmC;AACjC,WAAO,CAAC,KAAK,KAAK,SAAS;AACzB,UACE,CAAC,IAAI,UACL,IAAI,IAAI,mBAAmB,MAAM,WACjC,CAAC,KAAK,SAAS,cAAc;AAAA,QAAK,CAAC,eACjC,WAAW,KAAK,IAAI,WAAW;AAAA,MACjC,GACA;AACA,cAAM,OAAO,IAAI,IAAI,MAAM;AAC3B,YAAI,SAAS,WAAW,IAAI,GAAG,IAAI,GAAG,EAAE;AAAA,MAC1C,OAAO;AACL,aAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAuC;AACzC,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AACF;AAOO,MAAM,2BAAuB;AAAA,EAClC,CAAC,UAAoC,CAAC,MACpC,CAAC,QAAQ;AACP,UAAM,UAAU,IAAI,UAA+B,YAAY;AAC/D,QAAI,CAAC,QAAS,QAAO;AACrB,WAAO,IAAI,WAAW,OAAO,EAAE,cAAc;AAAA,EAC/C;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/middlewares/common/forceHTTPS.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils/index.js';\nimport { ExpressMiddleware } from '../../types/index.js';\n/**\n * The customization options for the middleware.\n *\n * @group Middlewares/ForceHTTPS\n */\nexport type ForceHTTPSOptions = {\n /**\n * A list of regular expressions to match routes that should be ignored.\n *\n * @default [/^\\/service\\//]\n */\n ignoredRoutes: RegExp[];\n};\n/**\n * A partial version of the {@link ForceHTTPSOptions}, to be used in the constructor and\n * the middleware creator.\n *\n * @group Middlewares/ForceHTTPS\n */\nexport type ForceHTTPSPartialOptions = Partial<ForceHTTPSOptions>;\n/**\n * Creates a middleware that forces all the traffic to be through HTTPS.\n *\n * @group Middleware Classes\n * @group Middlewares/ForceHTTPS\n * @prettierignore\n */\nexport class ForceHTTPS {\n /**\n * The customization options.\n */\n protected readonly _options: ForceHTTPSOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor(options: ForceHTTPSPartialOptions = {}) {\n this._options = {\n ignoredRoutes: [/^\\/service\\//],\n ...options,\n };\n }\n /**\n * Generates the middleware that redirects the traffic.\n */\n getMiddleware(): ExpressMiddleware {\n return (req, res, next) => {\n if (\n !req.secure &&\n req.get('X-Forwarded-Proto') !== 'https' &&\n !this._options.ignoredRoutes.some((expression) =>\n expression.test(req.originalUrl),\n )\n ) {\n const host = req.get('Host');\n res.redirect(`https://${host}${req.url}`);\n } else {\n next();\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<ForceHTTPSOptions> {\n return { ...this._options };\n }\n}\n/**\n * Creates the middleware that redirects the traffic to HTTPS.\n *\n * @group Middlewares\n * @group Middlewares/ForceHTTPS\n */\nexport const forceHTTPSMiddleware = middlewareCreator(\n (options: ForceHTTPSPartialOptions = {}) =>\n (app) => {\n const enabled = app.getConfig<boolean | undefined>('forceHTTPS');\n if (!enabled) return undefined;\n return new ForceHTTPS(options).getMiddleware();\n },\n);\n"],"mappings":"AAAA,SAAS,yBAAyB;AA6B3B,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA,EAIH;AAAA;AAAA;AAAA;AAAA,EAInB,YAAY,UAAoC,CAAC,GAAG;AAClD,SAAK,WAAW;AAAA,MACd,eAAe,CAAC,cAAc;AAAA,MAC9B,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAmC;AACjC,WAAO,CAAC,KAAK,KAAK,SAAS;AACzB,UACE,CAAC,IAAI,UACL,IAAI,IAAI,mBAAmB,MAAM,WACjC,CAAC,KAAK,SAAS,cAAc;AAAA,QAAK,CAAC,eACjC,WAAW,KAAK,IAAI,WAAW;AAAA,MACjC,GACA;AACA,cAAM,OAAO,IAAI,IAAI,MAAM;AAC3B,YAAI,SAAS,WAAW,IAAI,GAAG,IAAI,GAAG,EAAE;AAAA,MAC1C,OAAO;AACL,aAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAuC;AACzC,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AACF;AAOO,MAAM,uBAAuB;AAAA,EAClC,CAAC,UAAoC,CAAC,MACpC,CAAC,QAAQ;AACP,UAAM,UAAU,IAAI,UAA+B,YAAY;AAC/D,QAAI,CAAC,QAAS,QAAO;AACrB,WAAO,IAAI,WAAW,OAAO,EAAE,cAAc;AAAA,EAC/C;AACJ;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import * as _homer0_jimple from '@homer0/jimple';
2
- import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-C6I3NCC-.js';
2
+ import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-BlSpNHox.js';
3
3
  import { ExpressMiddleware } from '../../types/express.js';
4
4
  import '../../types/http.js';
5
5
  import 'https';
@@ -1,43 +1,17 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
- var hsts_exports = {};
22
- __export(hsts_exports, {
23
- HSTS: () => HSTS,
24
- hstsMiddleware: () => hstsMiddleware
25
- });
26
- module.exports = __toCommonJS(hsts_exports);
27
- var import_utils = require("../../utils");
1
+ import { middlewareCreator } from "../../utils/index.js";
28
2
  class HSTS {
3
+ /**
4
+ * The customization options for the header.
5
+ */
6
+ _options;
7
+ /**
8
+ * The value of the header that will be included in the responses.
9
+ */
10
+ _header;
29
11
  /**
30
12
  * @param options The options to construct the class.
31
13
  */
32
14
  constructor(options = {}) {
33
- /**
34
- * The customization options for the header.
35
- */
36
- __publicField(this, "_options");
37
- /**
38
- * The value of the header that will be included in the responses.
39
- */
40
- __publicField(this, "_header");
41
15
  this._options = {
42
16
  maxAge: 31536e3,
43
17
  includeSubDomains: true,
@@ -82,7 +56,7 @@ class HSTS {
82
56
  return directives.join("; ");
83
57
  }
84
58
  }
85
- const hstsMiddleware = (0, import_utils.middlewareCreator)(
59
+ const hstsMiddleware = middlewareCreator(
86
60
  (options = {}) => (app) => {
87
61
  const setting = app.getConfig("hsts");
88
62
  if (!setting?.enabled || typeof options.enabled !== "undefined" && !options.enabled)
@@ -90,9 +64,8 @@ const hstsMiddleware = (0, import_utils.middlewareCreator)(
90
64
  return new HSTS(options).getMiddleware();
91
65
  }
92
66
  );
93
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {
67
+ export {
95
68
  HSTS,
96
69
  hstsMiddleware
97
- });
70
+ };
98
71
  //# sourceMappingURL=hsts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/common/hsts.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils';\nimport { ExpressMiddleware } from '../../types';\n/**\n * The options to customize the HSTS header value.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security}\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewareOptions = {\n /**\n * The time, in seconds, that the browser should remember that a site is only to be\n * accessed using HTTPS.\n *\n * @default 31536000\n */\n maxAge: number;\n /**\n * Whether or not the rule should apply to all sub domains.\n *\n * @default true\n */\n includeSubDomains: boolean;\n /**\n * Whether or not to include on the major browsers'\n * preload list. This directive is not part of the specification, for more information\n * about it, you should check the MDN documentation for the header.\n *\n * @default false\n */\n preload: boolean;\n};\n/**\n * A partial version of the {@link HSTSMiddlewareOptions}, to be used in the constructor\n * and the middleware creator.\n *\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewarePartialOptions = Partial<HSTSMiddlewareOptions>;\n/**\n * The options for the middleware creator that will create the middleware, or not,\n * depending on the `enabled` option.\n *\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewareSettings = HSTSMiddlewarePartialOptions & {\n /**\n * If it's not `true`, it won't return the middleware.\n */\n enabled?: boolean;\n};\n/**\n * Generates a middleware that includes the HSTS header on the responses.\n *\n * @see {@link https://tools.ietf.org/html/rfc6797}\n * @group Middleware Classes\n * @group Middlewares/HSTS\n * @prettierignore\n */\nexport class HSTS {\n /**\n * The customization options for the header.\n */\n protected readonly _options: HSTSMiddlewareOptions;\n /**\n * The value of the header that will be included in the responses.\n */\n protected readonly _header: string;\n /**\n * @param options The options to construct the class.\n */\n constructor(options: HSTSMiddlewarePartialOptions = {}) {\n this._options = {\n maxAge: 31536000,\n includeSubDomains: true,\n preload: false,\n ...options,\n };\n this._header = this._buildHeader();\n }\n /**\n * Generates the middleware that includes the HSTS header on the responses.\n */\n getMiddleware(): ExpressMiddleware {\n return (_, res, next) => {\n res.setHeader('Strict-Transport-Security', this._header);\n next();\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<HSTSMiddlewareOptions> {\n return { ...this._options };\n }\n /**\n * The value of the header that will be included in the responses.\n */\n get header(): string {\n return this._header;\n }\n /**\n * Creates the header value based on the customization options.\n */\n protected _buildHeader(): string {\n const { maxAge, includeSubDomains, preload } = this._options;\n const directives = [`max-age=${maxAge}`];\n if (includeSubDomains) {\n directives.push('includeSubDomains');\n }\n\n if (preload) {\n directives.push('preload');\n }\n\n return directives.join('; ');\n }\n}\n/**\n * Creates the middleware that includes the HSTS header on the responses.\n *\n * @group Middlewares\n * @group Middlewares/HSTS\n */\nexport const hstsMiddleware = middlewareCreator(\n (options: HSTSMiddlewareSettings = {}) =>\n (app) => {\n const setting = app.getConfig<HSTSMiddlewareSettings | undefined>('hsts');\n if (\n !setting?.enabled ||\n (typeof options.enabled !== 'undefined' && !options.enabled)\n )\n return undefined;\n return new HSTS(options).getMiddleware();\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AA0D3B,MAAM,KAAK;AAAA;AAAA;AAAA;AAAA,EAYhB,YAAY,UAAwC,CAAC,GAAG;AARxD;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAKjB,SAAK,WAAW;AAAA,MACd,QAAQ;AAAA,MACR,mBAAmB;AAAA,MACnB,SAAS;AAAA,MACT,GAAG;AAAA,IACL;AACA,SAAK,UAAU,KAAK,aAAa;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAmC;AACjC,WAAO,CAAC,GAAG,KAAK,SAAS;AACvB,UAAI,UAAU,6BAA6B,KAAK,OAAO;AACvD,WAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAA2C;AAC7C,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,SAAiB;AACnB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAIU,eAAuB;AAC/B,UAAM,EAAE,QAAQ,mBAAmB,QAAQ,IAAI,KAAK;AACpD,UAAM,aAAa,CAAC,WAAW,MAAM,EAAE;AACvC,QAAI,mBAAmB;AACrB,iBAAW,KAAK,mBAAmB;AAAA,IACrC;AAEA,QAAI,SAAS;AACX,iBAAW,KAAK,SAAS;AAAA,IAC3B;AAEA,WAAO,WAAW,KAAK,IAAI;AAAA,EAC7B;AACF;AAOO,MAAM,qBAAiB;AAAA,EAC5B,CAAC,UAAkC,CAAC,MAClC,CAAC,QAAQ;AACP,UAAM,UAAU,IAAI,UAA8C,MAAM;AACxE,QACE,CAAC,SAAS,WACT,OAAO,QAAQ,YAAY,eAAe,CAAC,QAAQ;AAEpD,aAAO;AACT,WAAO,IAAI,KAAK,OAAO,EAAE,cAAc;AAAA,EACzC;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/middlewares/common/hsts.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils/index.js';\nimport { ExpressMiddleware } from '../../types/index.js';\n/**\n * The options to customize the HSTS header value.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security}\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewareOptions = {\n /**\n * The time, in seconds, that the browser should remember that a site is only to be\n * accessed using HTTPS.\n *\n * @default 31536000\n */\n maxAge: number;\n /**\n * Whether or not the rule should apply to all sub domains.\n *\n * @default true\n */\n includeSubDomains: boolean;\n /**\n * Whether or not to include on the major browsers'\n * preload list. This directive is not part of the specification, for more information\n * about it, you should check the MDN documentation for the header.\n *\n * @default false\n */\n preload: boolean;\n};\n/**\n * A partial version of the {@link HSTSMiddlewareOptions}, to be used in the constructor\n * and the middleware creator.\n *\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewarePartialOptions = Partial<HSTSMiddlewareOptions>;\n/**\n * The options for the middleware creator that will create the middleware, or not,\n * depending on the `enabled` option.\n *\n * @group Middlewares/HSTS\n */\nexport type HSTSMiddlewareSettings = HSTSMiddlewarePartialOptions & {\n /**\n * If it's not `true`, it won't return the middleware.\n */\n enabled?: boolean;\n};\n/**\n * Generates a middleware that includes the HSTS header on the responses.\n *\n * @see {@link https://tools.ietf.org/html/rfc6797}\n * @group Middleware Classes\n * @group Middlewares/HSTS\n * @prettierignore\n */\nexport class HSTS {\n /**\n * The customization options for the header.\n */\n protected readonly _options: HSTSMiddlewareOptions;\n /**\n * The value of the header that will be included in the responses.\n */\n protected readonly _header: string;\n /**\n * @param options The options to construct the class.\n */\n constructor(options: HSTSMiddlewarePartialOptions = {}) {\n this._options = {\n maxAge: 31536000,\n includeSubDomains: true,\n preload: false,\n ...options,\n };\n this._header = this._buildHeader();\n }\n /**\n * Generates the middleware that includes the HSTS header on the responses.\n */\n getMiddleware(): ExpressMiddleware {\n return (_, res, next) => {\n res.setHeader('Strict-Transport-Security', this._header);\n next();\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<HSTSMiddlewareOptions> {\n return { ...this._options };\n }\n /**\n * The value of the header that will be included in the responses.\n */\n get header(): string {\n return this._header;\n }\n /**\n * Creates the header value based on the customization options.\n */\n protected _buildHeader(): string {\n const { maxAge, includeSubDomains, preload } = this._options;\n const directives = [`max-age=${maxAge}`];\n if (includeSubDomains) {\n directives.push('includeSubDomains');\n }\n\n if (preload) {\n directives.push('preload');\n }\n\n return directives.join('; ');\n }\n}\n/**\n * Creates the middleware that includes the HSTS header on the responses.\n *\n * @group Middlewares\n * @group Middlewares/HSTS\n */\nexport const hstsMiddleware = middlewareCreator(\n (options: HSTSMiddlewareSettings = {}) =>\n (app) => {\n const setting = app.getConfig<HSTSMiddlewareSettings | undefined>('hsts');\n if (\n !setting?.enabled ||\n (typeof options.enabled !== 'undefined' && !options.enabled)\n )\n return undefined;\n return new HSTS(options).getMiddleware();\n },\n);\n"],"mappings":"AAAA,SAAS,yBAAyB;AA0D3B,MAAM,KAAK;AAAA;AAAA;AAAA;AAAA,EAIG;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA,EAInB,YAAY,UAAwC,CAAC,GAAG;AACtD,SAAK,WAAW;AAAA,MACd,QAAQ;AAAA,MACR,mBAAmB;AAAA,MACnB,SAAS;AAAA,MACT,GAAG;AAAA,IACL;AACA,SAAK,UAAU,KAAK,aAAa;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAmC;AACjC,WAAO,CAAC,GAAG,KAAK,SAAS;AACvB,UAAI,UAAU,6BAA6B,KAAK,OAAO;AACvD,WAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAA2C;AAC7C,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,SAAiB;AACnB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAIU,eAAuB;AAC/B,UAAM,EAAE,QAAQ,mBAAmB,QAAQ,IAAI,KAAK;AACpD,UAAM,aAAa,CAAC,WAAW,MAAM,EAAE;AACvC,QAAI,mBAAmB;AACrB,iBAAW,KAAK,mBAAmB;AAAA,IACrC;AAEA,QAAI,SAAS;AACX,iBAAW,KAAK,SAAS;AAAA,IAC3B;AAEA,WAAO,WAAW,KAAK,IAAI;AAAA,EAC7B;AACF;AAOO,MAAM,iBAAiB;AAAA,EAC5B,CAAC,UAAkC,CAAC,MAClC,CAAC,QAAQ;AACP,UAAM,UAAU,IAAI,UAA8C,MAAM;AACxE,QACE,CAAC,SAAS,WACT,OAAO,QAAQ,YAAY,eAAe,CAAC,QAAQ;AAEpD,aAAO;AACT,WAAO,IAAI,KAAK,OAAO,EAAE,cAAc;AAAA,EACzC;AACJ;","names":[]}
@@ -2,9 +2,7 @@ export { ErrorHandler, ErrorHandlerConstructorOptions, ErrorHandlerOptions, Erro
2
2
  export { ForceHTTPS, ForceHTTPSOptions, ForceHTTPSPartialOptions, forceHTTPSMiddleware } from './forceHTTPS.js';
3
3
  export { HSTS, HSTSMiddlewareOptions, HSTSMiddlewarePartialOptions, HSTSMiddlewareSettings, hstsMiddleware } from './hsts.js';
4
4
  import '@homer0/jimple';
5
- import '../../utils/fns/statuses.js';
6
- import 'statuses';
7
- import '../../index-C6I3NCC-.js';
5
+ import '../../index-BlSpNHox.js';
8
6
  import '../../types/express.js';
9
7
  import 'express';
10
8
  import '../../types/http.js';
@@ -17,6 +15,8 @@ import '@homer0/path-utils';
17
15
  import '@homer0/simple-logger';
18
16
  import '@homer0/simple-config';
19
17
  import '@homer0/events-hub';
18
+ import '../../utils/fns/statuses.js';
19
+ import 'statuses';
20
20
  import '../../services/common/httpError.js';
21
21
  import '../../services/common/appError.js';
22
22
  import '../../services/http/responsesBuilder.js';
@@ -1,27 +1,4 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var common_exports = {};
17
- module.exports = __toCommonJS(common_exports);
18
- __reExport(common_exports, require("./errorHandler"), module.exports);
19
- __reExport(common_exports, require("./forceHTTPS"), module.exports);
20
- __reExport(common_exports, require("./hsts"), module.exports);
21
- // Annotate the CommonJS export names for ESM import in node:
22
- 0 && (module.exports = {
23
- ...require("./errorHandler"),
24
- ...require("./forceHTTPS"),
25
- ...require("./hsts")
26
- });
1
+ export * from "./errorHandler.js";
2
+ export * from "./forceHTTPS.js";
3
+ export * from "./hsts.js";
27
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/common/index.ts"],"sourcesContent":["export * from './errorHandler';\nexport * from './forceHTTPS';\nexport * from './hsts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,2BAAd;AACA,2BAAc,yBADd;AAEA,2BAAc,mBAFd;","names":[]}
1
+ {"version":3,"sources":["../../../src/middlewares/common/index.ts"],"sourcesContent":["export * from './errorHandler.js';\nexport * from './forceHTTPS.js';\nexport * from './hsts.js';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import * as _homer0_jimple from '@homer0/jimple';
2
- import { l as Events, J as Jimpex, R as MiddlewareConnectFn } from '../../index-C6I3NCC-.js';
2
+ import { l as Events, J as Jimpex, R as MiddlewareConnectFn } from '../../index-BlSpNHox.js';
3
3
  import { AsyncExpressMiddleware } from '../../types/express.js';
4
4
  import { SendFile } from '../../services/common/sendFile.js';
5
5
  import { HTMLGenerator } from '../../services/html/htmlGenerator.js';
@@ -15,7 +15,7 @@ import '@homer0/simple-logger';
15
15
  import '@homer0/simple-config';
16
16
  import '@homer0/events-hub';
17
17
  import '../../services/frontend/frontendFs.js';
18
- import 'fs/promises';
18
+ import 'node:fs/promises';
19
19
  import '@homer0/deferred';
20
20
 
21
21
  /**
@@ -26,7 +26,7 @@ import '@homer0/deferred';
26
26
  type FastHTMLOptions = {
27
27
  /**
28
28
  * The name of the file the middleware will serve. If the {@link HTMLGenerator} service
29
- * is available, it will be overriden by the service.
29
+ * is available, it will be overridden by the service.
30
30
  *
31
31
  * @default 'index.html'
32
32
  */
@@ -106,7 +106,7 @@ declare class FastHTML {
106
106
  */
107
107
  protected readonly _sendFile: SendFile;
108
108
  /**
109
- * The application envent bus, to listen and get the list of "controlled routes" after
109
+ * The application event bus, to listen and get the list of "controlled routes" after
110
110
  * the application is started.
111
111
  */
112
112
  protected readonly _events: Events;
@@ -1,69 +1,47 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
- var fastHTML_exports = {};
22
- __export(fastHTML_exports, {
23
- FastHTML: () => FastHTML,
24
- fastHTMLMiddleware: () => fastHTMLMiddleware
25
- });
26
- module.exports = __toCommonJS(fastHTML_exports);
27
- var import_utils = require("../../utils");
1
+ import {
2
+ createRouteExpression,
3
+ middlewareCreator,
4
+ removeSlashes
5
+ } from "../../utils/index.js";
28
6
  class FastHTML {
7
+ /**
8
+ * The service that serves a file.
9
+ */
10
+ _sendFile;
11
+ /**
12
+ * The application event bus, to listen and get the list of "controlled routes" after
13
+ * the application is started.
14
+ */
15
+ _events;
16
+ /**
17
+ * A function to get a possible {@link HTMLGenerator}. This is injected as a "getter"
18
+ * to not interrupt the DIC "lifecycle": middlewares are initialized right when the
19
+ * app starts, and injecting a reference would force the service to be initialized
20
+ * too, even if a request is not being made.
21
+ */
22
+ _getHTMLGenerator;
23
+ /**
24
+ * The customization options for the middleware.
25
+ */
26
+ _options;
27
+ /**
28
+ * Whether or not the file is ready to be served. In case the middleware uses an
29
+ * {@link HTMLGenerator} service, the file needs to be generated before being available,
30
+ * and that's why this flag exists.
31
+ */
32
+ _fileReady = false;
33
+ /**
34
+ * A list of regular expression that match the routes controlled by the application.
35
+ * This is in case the `useAppRoutes` option is set to `true`; when the application gets
36
+ * started, an event listener will obtain all the top controlled routes, create regular
37
+ * expressions, and save them on this property.
38
+ */
39
+ _routeExpressions = [];
29
40
  /**
30
41
  * @param options The options to construct the class.
31
42
  * @throws If `ignoredRoutes` is empty and `useAppRoutes` is set to `false`.
32
43
  */
33
44
  constructor({ inject, ...options }) {
34
- /**
35
- * The service that serves a file.
36
- */
37
- __publicField(this, "_sendFile");
38
- /**
39
- * The application envent bus, to listen and get the list of "controlled routes" after
40
- * the application is started.
41
- */
42
- __publicField(this, "_events");
43
- /**
44
- * A function to get a possible {@link HTMLGenerator}. This is injected as a "getter"
45
- * to not interrupt the DIC "lifecycle": middlewares are initialized right when the
46
- * app starts, and injecting a reference would force the service to be initialized
47
- * too, even if a request is not being made.
48
- */
49
- __publicField(this, "_getHTMLGenerator");
50
- /**
51
- * The customization options for the middleware.
52
- */
53
- __publicField(this, "_options");
54
- /**
55
- * Whether or not the file is ready to be served. In case the middleware uses an
56
- * {@link HTMLGenerator} service, the file needs to be generated before being available,
57
- * and that's why this flag exists.
58
- */
59
- __publicField(this, "_fileReady", false);
60
- /**
61
- * A list of regular expression that match the routes controlled by the application.
62
- * This is in case the `useAppRoutes` option is set to `true`; when the application gets
63
- * started, an event listener will obtain all the top controlled routes, create regular
64
- * expressions, and save them on this property.
65
- */
66
- __publicField(this, "_routeExpressions", []);
67
45
  this._sendFile = inject.sendFile;
68
46
  this._events = inject.events;
69
47
  this._getHTMLGenerator = inject.getHTMLGenerator || (() => void 0);
@@ -138,9 +116,9 @@ class FastHTML {
138
116
  const [routeExpressions] = app.routes.reduce(
139
117
  (acc, route) => {
140
118
  const [expressions, processed] = acc;
141
- const clean = (0, import_utils.removeSlashes)(route).trim();
119
+ const clean = removeSlashes(route).trim();
142
120
  if (!clean || processed.includes(clean)) return acc;
143
- expressions.push((0, import_utils.createRouteExpression)(clean));
121
+ expressions.push(createRouteExpression(clean));
144
122
  processed.push(clean);
145
123
  return acc;
146
124
  },
@@ -160,7 +138,7 @@ class FastHTML {
160
138
  return this._options.ignoredRoutes.some((expression) => route.match(expression)) || this._routeExpressions.some((expression) => route.match(expression));
161
139
  }
162
140
  }
163
- const fastHTMLMiddleware = (0, import_utils.middlewareCreator)(
141
+ const fastHTMLMiddleware = middlewareCreator(
164
142
  (options = {}) => (app) => {
165
143
  const { htmlGeneratorServiceName = "htmlGenerator", ...rest } = options;
166
144
  return new FastHTML({
@@ -173,9 +151,8 @@ const fastHTMLMiddleware = (0, import_utils.middlewareCreator)(
173
151
  }).getMiddleware();
174
152
  }
175
153
  );
176
- // Annotate the CommonJS export names for ESM import in node:
177
- 0 && (module.exports = {
154
+ export {
178
155
  FastHTML,
179
156
  fastHTMLMiddleware
180
- });
157
+ };
181
158
  //# sourceMappingURL=fastHTML.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/html/fastHTML.ts"],"sourcesContent":["import { createRouteExpression, middlewareCreator, removeSlashes } from '../../utils';\nimport type { HTMLGenerator, SendFile } from '../../services';\nimport type { AsyncExpressMiddleware, Response, NextFunction, Events } from '../../types';\n/**\n * The options to customize the behavior of the middleware.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLOptions = {\n /**\n * The name of the file the middleware will serve. If the {@link HTMLGenerator} service\n * is available, it will be overriden by the service.\n *\n * @default 'index.html'\n */\n file: string;\n /**\n * A list of regular expressions to match request paths that should be ignored by the\n * middleware.\n *\n * @default [/\\.ico$/i]\n */\n ignoredRoutes: RegExp[];\n /**\n * If `true`, {@link FastHTML} will get the list of all the routes controlled by the\n * application, and will use them to validate the incoming requests (in addition to the\n * `ignore` list): If a request URL doesn't match with any of the \"controlled routes\",\n * it will serve the HTML file.\n *\n * @default true\n */\n useAppRoutes: boolean;\n};\n/**\n * The options to construct a {@link FastHTML}.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLConstructorOptions = Partial<FastHTMLOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n sendFile: SendFile;\n events: Events;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n getHTMLGenerator?: () => HTMLGenerator | undefined;\n };\n};\n/**\n * The options for the middleware creator that will mount an instance of {@link FastHTML}.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLMiddlewareOptions = Partial<FastHTMLOptions> & {\n /**\n * The name of an {@link HTMLGenerator} service already available in the application.\n *\n * @default 'htmlGenerator'\n */\n htmlGeneratorServiceName?: string;\n};\n/**\n * It's common for an app to show an HTML view when no route was able to handle a request,\n * so the idea behind this middleware is to avoid going to every middleware and controller\n * and just specify that if the request is not for a route handled by a controller, just\n * serve the HTML and avoid processing unnecessary data.\n *\n * A simple example: The app has a route `/backend` that a frontend uses to get\n * information.\n * This middleware can be used to only allow the execution of middlewares and controllers\n * when the request route is for `/backend`.\n *\n * **Disclaimer**: Managing statics files with Express is not a best practice, but there\n * are scenarios where there is not other choice.\n *\n * @group Middleware Classes\n * @group Middlewares/FastHTML\n * @prettierignore\n */\nexport class FastHTML {\n /**\n * The service that serves a file.\n */\n protected readonly _sendFile: SendFile;\n /**\n * The application envent bus, to listen and get the list of \"controlled routes\" after\n * the application is started.\n */\n protected readonly _events: Events;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n protected readonly _getHTMLGenerator: () => HTMLGenerator | undefined;\n /**\n * The customization options for the middleware.\n */\n protected _options: FastHTMLOptions;\n /**\n * Whether or not the file is ready to be served. In case the middleware uses an\n * {@link HTMLGenerator} service, the file needs to be generated before being available,\n * and that's why this flag exists.\n */\n protected _fileReady: boolean = false;\n /**\n * A list of regular expression that match the routes controlled by the application.\n * This is in case the `useAppRoutes` option is set to `true`; when the application gets\n * started, an event listener will obtain all the top controlled routes, create regular\n * expressions, and save them on this property.\n */\n protected _routeExpressions: RegExp[] = [];\n /**\n * @param options The options to construct the class.\n * @throws If `ignoredRoutes` is empty and `useAppRoutes` is set to `false`.\n */\n constructor({ inject, ...options }: FastHTMLConstructorOptions) {\n this._sendFile = inject.sendFile;\n this._events = inject.events;\n this._getHTMLGenerator = inject.getHTMLGenerator || (() => undefined);\n this._options = {\n file: 'index.html',\n ignoredRoutes: [/\\.ico$/i],\n useAppRoutes: true,\n ...options,\n };\n\n if (!this._options.ignoredRoutes.length && !this._options.useAppRoutes) {\n throw new Error('You must provide either `ignoredRoutes` or `useAppRoutes`');\n }\n\n if (this._options.useAppRoutes) {\n this._setupEvents();\n }\n }\n /**\n * Generates the middleware that serves the HTML file.\n */\n getMiddleware(): AsyncExpressMiddleware {\n return async (req, res, next) => {\n // If the route should be ignored, move to the next middleware.\n if (this._shouldIgnoreRoute(req.originalUrl)) {\n next();\n return;\n }\n\n // If the file is ready to be served, serve it.\n if (this._fileReady) {\n this._sendResponse(res, next);\n return;\n }\n\n const htmlGenerator = this._getHTMLGenerator();\n // If there's no generator, switch the flag and just serve the file.\n if (!htmlGenerator) {\n this._fileReady = true;\n this._sendResponse(res, next);\n return;\n }\n\n try {\n // Wait for the HTML to be generated.\n await htmlGenerator.whenReady();\n // Update the local option.\n this._options.file = htmlGenerator.options.file;\n // Switch the flag and serve the file.\n this._fileReady = true;\n this._sendResponse(res, next);\n } catch (error) {\n next(error);\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<FastHTMLOptions> {\n return { ...this._options };\n }\n /**\n * Serves the HTML file to the response.\n *\n * @param res The response object generated by the application.\n * @param next The function to call the next middleware.\n */\n protected _sendResponse(res: Response, next: NextFunction): void {\n res.setHeader('Content-Type', 'text/html');\n this._sendFile({\n res,\n next,\n filepath: this._options.file,\n });\n }\n /**\n * Adds the event listener that obtains the list of \"controlled routes\" when\n * `useAppRoutes` is set to `true`.\n */\n protected _setupEvents() {\n this._events.once('afterStart', ({ app }) => {\n const [routeExpressions] = app.routes.reduce<[RegExp[], string[]]>(\n (acc, route) => {\n const [expressions, processed] = acc;\n const clean = removeSlashes(route).trim();\n if (!clean || processed.includes(clean)) return acc;\n expressions.push(createRouteExpression(clean));\n processed.push(clean);\n return acc;\n },\n [[], []],\n );\n this._routeExpressions.push(...routeExpressions);\n });\n }\n /**\n * Validates whether a route should be ignored or not. The method checks first against\n * the `ignore` option, and then against the list of \"controlled routes\" if\n * `useAppRoutes` is set to `true`.\n *\n * @param route The route to validate.\n */\n protected _shouldIgnoreRoute(route: string): boolean {\n return (\n this._options.ignoredRoutes.some((expression) => route.match(expression)) ||\n this._routeExpressions.some((expression) => route.match(expression))\n );\n }\n}\n/**\n * Creates the middleware that filters the routes and serves an HTML before the\n * application gets to evaluate whether there's a controller for the request or not.\n *\n * @group Middlewares\n * @group Middlewares/FastHTML\n */\nexport const fastHTMLMiddleware = middlewareCreator(\n (options: FastHTMLMiddlewareOptions = {}) =>\n (app) => {\n const { htmlGeneratorServiceName = 'htmlGenerator', ...rest } = options;\n return new FastHTML({\n inject: {\n events: app.get('events'),\n sendFile: app.get('sendFile'),\n getHTMLGenerator: () => app.try(htmlGeneratorServiceName),\n },\n ...rest,\n }).getMiddleware();\n },\n);\n"],"mappings":"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","names":[]}
1
+ {"version":3,"sources":["../../../src/middlewares/html/fastHTML.ts"],"sourcesContent":["import {\n createRouteExpression,\n middlewareCreator,\n removeSlashes,\n} from '../../utils/index.js';\nimport type { HTMLGenerator, SendFile } from '../../services/index.js';\nimport type {\n AsyncExpressMiddleware,\n Response,\n NextFunction,\n Events,\n} from '../../types/index.js';\n/**\n * The options to customize the behavior of the middleware.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLOptions = {\n /**\n * The name of the file the middleware will serve. If the {@link HTMLGenerator} service\n * is available, it will be overridden by the service.\n *\n * @default 'index.html'\n */\n file: string;\n /**\n * A list of regular expressions to match request paths that should be ignored by the\n * middleware.\n *\n * @default [/\\.ico$/i]\n */\n ignoredRoutes: RegExp[];\n /**\n * If `true`, {@link FastHTML} will get the list of all the routes controlled by the\n * application, and will use them to validate the incoming requests (in addition to the\n * `ignore` list): If a request URL doesn't match with any of the \"controlled routes\",\n * it will serve the HTML file.\n *\n * @default true\n */\n useAppRoutes: boolean;\n};\n/**\n * The options to construct a {@link FastHTML}.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLConstructorOptions = Partial<FastHTMLOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n sendFile: SendFile;\n events: Events;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n getHTMLGenerator?: () => HTMLGenerator | undefined;\n };\n};\n/**\n * The options for the middleware creator that will mount an instance of {@link FastHTML}.\n *\n * @group Middlewares/FastHTML\n */\nexport type FastHTMLMiddlewareOptions = Partial<FastHTMLOptions> & {\n /**\n * The name of an {@link HTMLGenerator} service already available in the application.\n *\n * @default 'htmlGenerator'\n */\n htmlGeneratorServiceName?: string;\n};\n/**\n * It's common for an app to show an HTML view when no route was able to handle a request,\n * so the idea behind this middleware is to avoid going to every middleware and controller\n * and just specify that if the request is not for a route handled by a controller, just\n * serve the HTML and avoid processing unnecessary data.\n *\n * A simple example: The app has a route `/backend` that a frontend uses to get\n * information.\n * This middleware can be used to only allow the execution of middlewares and controllers\n * when the request route is for `/backend`.\n *\n * **Disclaimer**: Managing statics files with Express is not a best practice, but there\n * are scenarios where there is not other choice.\n *\n * @group Middleware Classes\n * @group Middlewares/FastHTML\n * @prettierignore\n */\nexport class FastHTML {\n /**\n * The service that serves a file.\n */\n protected readonly _sendFile: SendFile;\n /**\n * The application event bus, to listen and get the list of \"controlled routes\" after\n * the application is started.\n */\n protected readonly _events: Events;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n protected readonly _getHTMLGenerator: () => HTMLGenerator | undefined;\n /**\n * The customization options for the middleware.\n */\n protected _options: FastHTMLOptions;\n /**\n * Whether or not the file is ready to be served. In case the middleware uses an\n * {@link HTMLGenerator} service, the file needs to be generated before being available,\n * and that's why this flag exists.\n */\n protected _fileReady: boolean = false;\n /**\n * A list of regular expression that match the routes controlled by the application.\n * This is in case the `useAppRoutes` option is set to `true`; when the application gets\n * started, an event listener will obtain all the top controlled routes, create regular\n * expressions, and save them on this property.\n */\n protected _routeExpressions: RegExp[] = [];\n /**\n * @param options The options to construct the class.\n * @throws If `ignoredRoutes` is empty and `useAppRoutes` is set to `false`.\n */\n constructor({ inject, ...options }: FastHTMLConstructorOptions) {\n this._sendFile = inject.sendFile;\n this._events = inject.events;\n this._getHTMLGenerator = inject.getHTMLGenerator || (() => undefined);\n this._options = {\n file: 'index.html',\n ignoredRoutes: [/\\.ico$/i],\n useAppRoutes: true,\n ...options,\n };\n\n if (!this._options.ignoredRoutes.length && !this._options.useAppRoutes) {\n throw new Error('You must provide either `ignoredRoutes` or `useAppRoutes`');\n }\n\n if (this._options.useAppRoutes) {\n this._setupEvents();\n }\n }\n /**\n * Generates the middleware that serves the HTML file.\n */\n getMiddleware(): AsyncExpressMiddleware {\n return async (req, res, next) => {\n // If the route should be ignored, move to the next middleware.\n if (this._shouldIgnoreRoute(req.originalUrl)) {\n next();\n return;\n }\n\n // If the file is ready to be served, serve it.\n if (this._fileReady) {\n this._sendResponse(res, next);\n return;\n }\n\n const htmlGenerator = this._getHTMLGenerator();\n // If there's no generator, switch the flag and just serve the file.\n if (!htmlGenerator) {\n this._fileReady = true;\n this._sendResponse(res, next);\n return;\n }\n\n try {\n // Wait for the HTML to be generated.\n await htmlGenerator.whenReady();\n // Update the local option.\n this._options.file = htmlGenerator.options.file;\n // Switch the flag and serve the file.\n this._fileReady = true;\n this._sendResponse(res, next);\n } catch (error) {\n next(error);\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<FastHTMLOptions> {\n return { ...this._options };\n }\n /**\n * Serves the HTML file to the response.\n *\n * @param res The response object generated by the application.\n * @param next The function to call the next middleware.\n */\n protected _sendResponse(res: Response, next: NextFunction): void {\n res.setHeader('Content-Type', 'text/html');\n this._sendFile({\n res,\n next,\n filepath: this._options.file,\n });\n }\n /**\n * Adds the event listener that obtains the list of \"controlled routes\" when\n * `useAppRoutes` is set to `true`.\n */\n protected _setupEvents() {\n this._events.once('afterStart', ({ app }) => {\n const [routeExpressions] = app.routes.reduce<[RegExp[], string[]]>(\n (acc, route) => {\n const [expressions, processed] = acc;\n const clean = removeSlashes(route).trim();\n if (!clean || processed.includes(clean)) return acc;\n expressions.push(createRouteExpression(clean));\n processed.push(clean);\n return acc;\n },\n [[], []],\n );\n this._routeExpressions.push(...routeExpressions);\n });\n }\n /**\n * Validates whether a route should be ignored or not. The method checks first against\n * the `ignore` option, and then against the list of \"controlled routes\" if\n * `useAppRoutes` is set to `true`.\n *\n * @param route The route to validate.\n */\n protected _shouldIgnoreRoute(route: string): boolean {\n return (\n this._options.ignoredRoutes.some((expression) => route.match(expression)) ||\n this._routeExpressions.some((expression) => route.match(expression))\n );\n }\n}\n/**\n * Creates the middleware that filters the routes and serves an HTML before the\n * application gets to evaluate whether there's a controller for the request or not.\n *\n * @group Middlewares\n * @group Middlewares/FastHTML\n */\nexport const fastHTMLMiddleware = middlewareCreator(\n (options: FastHTMLMiddlewareOptions = {}) =>\n (app) => {\n const { htmlGeneratorServiceName = 'htmlGenerator', ...rest } = options;\n return new FastHTML({\n inject: {\n events: app.get('events'),\n sendFile: app.get('sendFile'),\n getHTMLGenerator: () => app.try(htmlGeneratorServiceName),\n },\n ...rest,\n }).getMiddleware();\n },\n);\n"],"mappings":"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","names":[]}
@@ -1,7 +1,7 @@
1
1
  export { FastHTML, FastHTMLConstructorOptions, FastHTMLMiddlewareOptions, FastHTMLOptions, fastHTMLMiddleware } from './fastHTML.js';
2
2
  export { ShowHTML, ShowHTMLConstructorOptions, ShowHTMLMiddlewareOptions, ShowHTMLOptions, showHTMLMiddleware } from './showHTML.js';
3
3
  import '@homer0/jimple';
4
- import '../../index-C6I3NCC-.js';
4
+ import '../../index-BlSpNHox.js';
5
5
  import '../../types/express.js';
6
6
  import 'express';
7
7
  import '../../types/http.js';
@@ -17,5 +17,5 @@ import '@homer0/events-hub';
17
17
  import '../../services/common/sendFile.js';
18
18
  import '../../services/html/htmlGenerator.js';
19
19
  import '../../services/frontend/frontendFs.js';
20
- import 'fs/promises';
20
+ import 'node:fs/promises';
21
21
  import '@homer0/deferred';
@@ -1,25 +1,3 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var html_exports = {};
17
- module.exports = __toCommonJS(html_exports);
18
- __reExport(html_exports, require("./fastHTML"), module.exports);
19
- __reExport(html_exports, require("./showHTML"), module.exports);
20
- // Annotate the CommonJS export names for ESM import in node:
21
- 0 && (module.exports = {
22
- ...require("./fastHTML"),
23
- ...require("./showHTML")
24
- });
1
+ export * from "./fastHTML.js";
2
+ export * from "./showHTML.js";
25
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/html/index.ts"],"sourcesContent":["export * from './fastHTML';\nexport * from './showHTML';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,yBAAc,uBAAd;AACA,yBAAc,uBADd;","names":[]}
1
+ {"version":3,"sources":["../../../src/middlewares/html/index.ts"],"sourcesContent":["export * from './fastHTML.js';\nexport * from './showHTML.js';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import * as _homer0_jimple from '@homer0/jimple';
2
- import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-C6I3NCC-.js';
2
+ import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-BlSpNHox.js';
3
3
  import { AsyncExpressMiddleware } from '../../types/express.js';
4
4
  import { SendFile } from '../../services/common/sendFile.js';
5
5
  import { HTMLGenerator } from '../../services/html/htmlGenerator.js';
@@ -15,7 +15,7 @@ import '@homer0/simple-logger';
15
15
  import '@homer0/simple-config';
16
16
  import '@homer0/events-hub';
17
17
  import '../../services/frontend/frontendFs.js';
18
- import 'fs/promises';
18
+ import 'node:fs/promises';
19
19
  import '@homer0/deferred';
20
20
 
21
21
  /**
@@ -26,7 +26,7 @@ import '@homer0/deferred';
26
26
  type ShowHTMLOptions = {
27
27
  /**
28
28
  * The name of the file the middleware will serve. If the {@link HTMLGenerator} service
29
- * is available, it will be overriden by the service.
29
+ * is available, it will be overridden by the service.
30
30
  *
31
31
  * @default 'index.html'
32
32
  */