@depup/nitro 3.0.260311-beta-depup.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 (370) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +32 -0
  3. package/changes.json +14 -0
  4. package/dist/THIRD-PARTY-LICENSES.md +1646 -0
  5. package/dist/_build/common.mjs +29361 -0
  6. package/dist/_build/rolldown.mjs +173 -0
  7. package/dist/_build/rollup.mjs +194 -0
  8. package/dist/_build/vite.build.mjs +18 -0
  9. package/dist/_chunks/nitro.mjs +1159 -0
  10. package/dist/_chunks/nitro2.mjs +102 -0
  11. package/dist/_chunks/nitro3.mjs +129 -0
  12. package/dist/_chunks/utils.mjs +272 -0
  13. package/dist/_common.mjs +35 -0
  14. package/dist/_dev.d.mts +12 -0
  15. package/dist/_dev.mjs +519 -0
  16. package/dist/_libs/_.mjs +3 -0
  17. package/dist/_libs/_2.mjs +2 -0
  18. package/dist/_libs/_3.mjs +3 -0
  19. package/dist/_libs/_4.mjs +2 -0
  20. package/dist/_libs/_5.mjs +3 -0
  21. package/dist/_libs/_6.mjs +4 -0
  22. package/dist/_libs/_7.mjs +5 -0
  23. package/dist/_libs/c12+rc9.mjs +812 -0
  24. package/dist/_libs/c12+readdirp+chokidar.d.mts +230 -0
  25. package/dist/_libs/citty.mjs +361 -0
  26. package/dist/_libs/commondir+is-reference.mjs +1311 -0
  27. package/dist/_libs/compatx.d.mts +47 -0
  28. package/dist/_libs/compatx.mjs +45 -0
  29. package/dist/_libs/esbuild.d.mts +20 -0
  30. package/dist/_libs/escape-string-regexp.mjs +7 -0
  31. package/dist/_libs/estree+pluginutils.d.mts +241 -0
  32. package/dist/_libs/estree-walker.mjs +184 -0
  33. package/dist/_libs/exsolve.d.mts +1 -0
  34. package/dist/_libs/hasown+resolve+deepmerge.mjs +1949 -0
  35. package/dist/_libs/httpxy.d.mts +82 -0
  36. package/dist/_libs/httpxy.mjs +671 -0
  37. package/dist/_libs/js-tokens.d.mts +1 -0
  38. package/dist/_libs/klona.mjs +37 -0
  39. package/dist/_libs/magic-string.d.mts +220 -0
  40. package/dist/_libs/mlly.d.mts +57 -0
  41. package/dist/_libs/nypm+tinyexec.mjs +845 -0
  42. package/dist/_libs/perfect-debounce.mjs +88 -0
  43. package/dist/_libs/pkg-types.d.mts +23 -0
  44. package/dist/_libs/plugin-alias.mjs +64 -0
  45. package/dist/_libs/plugin-inject.mjs +131 -0
  46. package/dist/_libs/plugin-json.mjs +34 -0
  47. package/dist/_libs/pluginutils.mjs +646 -0
  48. package/dist/_libs/readdirp+chokidar.mjs +1606 -0
  49. package/dist/_libs/remapping.mjs +115 -0
  50. package/dist/_libs/resolve-uri+gen-mapping.mjs +442 -0
  51. package/dist/_libs/rou3.d.mts +44 -0
  52. package/dist/_libs/rou3.mjs +496 -0
  53. package/dist/_libs/std-env.d.mts +12 -0
  54. package/dist/_libs/strip-literal.d.mts +1 -0
  55. package/dist/_libs/tsconfck.mjs +813 -0
  56. package/dist/_libs/ultrahtml.mjs +127 -0
  57. package/dist/_libs/unimport+unplugin.mjs +1684 -0
  58. package/dist/_libs/unplugin+unimport.d.mts +423 -0
  59. package/dist/_libs/unwasm.d.mts +29 -0
  60. package/dist/_presets.mjs +1759 -0
  61. package/dist/builder.d.mts +64 -0
  62. package/dist/builder.mjs +15 -0
  63. package/dist/cli/_chunks/build.mjs +47 -0
  64. package/dist/cli/_chunks/common.mjs +14 -0
  65. package/dist/cli/_chunks/deploy.mjs +40 -0
  66. package/dist/cli/_chunks/dev.mjs +62 -0
  67. package/dist/cli/_chunks/docs.mjs +30 -0
  68. package/dist/cli/_chunks/list.mjs +25 -0
  69. package/dist/cli/_chunks/prepare.mjs +17 -0
  70. package/dist/cli/_chunks/preview.mjs +51 -0
  71. package/dist/cli/_chunks/run.mjs +53 -0
  72. package/dist/cli/_chunks/task.mjs +14 -0
  73. package/dist/cli/index.d.mts +1 -0
  74. package/dist/cli/index.mjs +22 -0
  75. package/dist/node_modules/@poppinss/colors/build/index.js +139 -0
  76. package/dist/node_modules/@poppinss/colors/package.json +118 -0
  77. package/dist/node_modules/@poppinss/dumper/build/chunk-26HALFTP.js +602 -0
  78. package/dist/node_modules/@poppinss/dumper/build/formatters/console/main.js +441 -0
  79. package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +725 -0
  80. package/dist/node_modules/@poppinss/dumper/package.json +122 -0
  81. package/dist/node_modules/@poppinss/exception/build/index.js +44 -0
  82. package/dist/node_modules/@poppinss/exception/package.json +109 -0
  83. package/dist/node_modules/@sindresorhus/is/distribution/index.js +1354 -0
  84. package/dist/node_modules/@sindresorhus/is/distribution/utilities.js +3 -0
  85. package/dist/node_modules/@sindresorhus/is/package.json +81 -0
  86. package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -0
  87. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -0
  88. package/dist/node_modules/@speed-highlight/core/package.json +94 -0
  89. package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
  90. package/dist/node_modules/cookie-es/package.json +37 -0
  91. package/dist/node_modules/croner/dist/croner.js +1 -0
  92. package/dist/node_modules/croner/package.json +73 -0
  93. package/dist/node_modules/defu/dist/defu.mjs +69 -0
  94. package/dist/node_modules/defu/package.json +43 -0
  95. package/dist/node_modules/destr/dist/index.mjs +72 -0
  96. package/dist/node_modules/destr/package.json +47 -0
  97. package/dist/node_modules/error-stack-parser-es/dist/index.mjs +38 -0
  98. package/dist/node_modules/error-stack-parser-es/dist/lite.mjs +167 -0
  99. package/dist/node_modules/error-stack-parser-es/package.json +83 -0
  100. package/dist/node_modules/get-port-please/dist/index.mjs +430 -0
  101. package/dist/node_modules/get-port-please/package.json +39 -0
  102. package/dist/node_modules/kleur/index.mjs +110 -0
  103. package/dist/node_modules/kleur/package.json +51 -0
  104. package/dist/node_modules/rendu/dist/index.mjs +380 -0
  105. package/dist/node_modules/rendu/package.json +47 -0
  106. package/dist/node_modules/scule/dist/index.mjs +80 -0
  107. package/dist/node_modules/scule/package.json +43 -0
  108. package/dist/node_modules/source-map/lib/array-set.js +100 -0
  109. package/dist/node_modules/source-map/lib/base64-vlq.js +94 -0
  110. package/dist/node_modules/source-map/lib/base64.js +19 -0
  111. package/dist/node_modules/source-map/lib/binary-search.js +113 -0
  112. package/dist/node_modules/source-map/lib/mapping-list.js +83 -0
  113. package/dist/node_modules/source-map/lib/mappings.wasm +0 -0
  114. package/dist/node_modules/source-map/lib/read-wasm.js +27 -0
  115. package/dist/node_modules/source-map/lib/source-map-consumer.js +1081 -0
  116. package/dist/node_modules/source-map/lib/source-map-generator.js +439 -0
  117. package/dist/node_modules/source-map/lib/source-node.js +430 -0
  118. package/dist/node_modules/source-map/lib/url.js +13 -0
  119. package/dist/node_modules/source-map/lib/util.js +444 -0
  120. package/dist/node_modules/source-map/lib/wasm.js +138 -0
  121. package/dist/node_modules/source-map/package.json +79 -0
  122. package/dist/node_modules/source-map/source-map.js +10 -0
  123. package/dist/node_modules/supports-color/index.js +202 -0
  124. package/dist/node_modules/supports-color/package.json +64 -0
  125. package/dist/node_modules/ufo/dist/index.mjs +645 -0
  126. package/dist/node_modules/ufo/package.json +48 -0
  127. package/dist/node_modules/unctx/dist/index.mjs +131 -0
  128. package/dist/node_modules/unctx/package.json +67 -0
  129. package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
  130. package/dist/node_modules/youch/build/index.js +212 -0
  131. package/dist/node_modules/youch/build/public/error_cause/style.css +5 -0
  132. package/dist/node_modules/youch/build/public/error_info/script.js +13 -0
  133. package/dist/node_modules/youch/build/public/error_info/style.css +145 -0
  134. package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
  135. package/dist/node_modules/youch/build/public/error_stack/script.js +72 -0
  136. package/dist/node_modules/youch/build/public/error_stack/style.css +219 -0
  137. package/dist/node_modules/youch/build/public/error_stack_source/style.css +123 -0
  138. package/dist/node_modules/youch/build/public/header/script.js +14 -0
  139. package/dist/node_modules/youch/build/public/header/style.css +56 -0
  140. package/dist/node_modules/youch/build/public/layout/script.js +12 -0
  141. package/dist/node_modules/youch/build/public/layout/style.css +435 -0
  142. package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
  143. package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
  144. package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
  145. package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
  146. package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
  147. package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
  148. package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
  149. package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
  150. package/dist/node_modules/youch/package.json +135 -0
  151. package/dist/node_modules/youch-core/build/index.js +316 -0
  152. package/dist/node_modules/youch-core/package.json +124 -0
  153. package/dist/presets/_nitro/runtime/nitro-dev.mjs +20 -0
  154. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +15 -0
  155. package/dist/presets/_nitro/runtime/service-worker.mjs +23 -0
  156. package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +14 -0
  157. package/dist/presets/aws-lambda/runtime/_utils.mjs +116 -0
  158. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +31 -0
  159. package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +13 -0
  160. package/dist/presets/azure/runtime/_utils.mjs +50 -0
  161. package/dist/presets/azure/runtime/azure-swa.mjs +30 -0
  162. package/dist/presets/bun/runtime/bun.mjs +40 -0
  163. package/dist/presets/cloudflare/runtime/_module-handler.mjs +87 -0
  164. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +72 -0
  165. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +17 -0
  166. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +39 -0
  167. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +96 -0
  168. package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
  169. package/dist/presets/deno/runtime/deno-deploy.mjs +19 -0
  170. package/dist/presets/deno/runtime/deno-server.mjs +39 -0
  171. package/dist/presets/netlify/runtime/netlify-edge.mjs +20 -0
  172. package/dist/presets/netlify/runtime/netlify.mjs +20 -0
  173. package/dist/presets/node/runtime/node-cluster.mjs +54 -0
  174. package/dist/presets/node/runtime/node-middleware.mjs +14 -0
  175. package/dist/presets/node/runtime/node-server.mjs +47 -0
  176. package/dist/presets/standard/runtime/server.mjs +4 -0
  177. package/dist/presets/stormkit/runtime/stormkit.mjs +27 -0
  178. package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
  179. package/dist/presets/vercel/runtime/isr.mjs +19 -0
  180. package/dist/presets/vercel/runtime/vercel.node.mjs +24 -0
  181. package/dist/presets/vercel/runtime/vercel.web.mjs +23 -0
  182. package/dist/presets/winterjs/runtime/winterjs.mjs +91 -0
  183. package/dist/presets/zeabur/runtime/zeabur.mjs +4 -0
  184. package/dist/presets/zephyr/runtime/server.mjs +3 -0
  185. package/dist/runtime/app.d.mts +1 -0
  186. package/dist/runtime/app.mjs +1 -0
  187. package/dist/runtime/cache.d.mts +1 -0
  188. package/dist/runtime/cache.mjs +1 -0
  189. package/dist/runtime/config.d.mts +3 -0
  190. package/dist/runtime/config.mjs +4 -0
  191. package/dist/runtime/context.d.mts +1 -0
  192. package/dist/runtime/context.mjs +1 -0
  193. package/dist/runtime/database.d.mts +1 -0
  194. package/dist/runtime/database.mjs +1 -0
  195. package/dist/runtime/internal/app.d.mts +16 -0
  196. package/dist/runtime/internal/app.mjs +208 -0
  197. package/dist/runtime/internal/cache.d.mts +7 -0
  198. package/dist/runtime/internal/cache.mjs +41 -0
  199. package/dist/runtime/internal/context.d.mts +14 -0
  200. package/dist/runtime/internal/context.mjs +24 -0
  201. package/dist/runtime/internal/database.d.mts +2 -0
  202. package/dist/runtime/internal/database.mjs +12 -0
  203. package/dist/runtime/internal/empty.mjs +0 -0
  204. package/dist/runtime/internal/error/dev.d.mts +10 -0
  205. package/dist/runtime/internal/error/dev.mjs +121 -0
  206. package/dist/runtime/internal/error/hooks.d.mts +1 -0
  207. package/dist/runtime/internal/error/hooks.mjs +9 -0
  208. package/dist/runtime/internal/error/prod.d.mts +6 -0
  209. package/dist/runtime/internal/error/prod.mjs +40 -0
  210. package/dist/runtime/internal/error/utils.d.mts +8 -0
  211. package/dist/runtime/internal/error/utils.mjs +3 -0
  212. package/dist/runtime/internal/meta.d.mts +2 -0
  213. package/dist/runtime/internal/meta.mjs +3 -0
  214. package/dist/runtime/internal/plugin.d.mts +3 -0
  215. package/dist/runtime/internal/plugin.mjs +4 -0
  216. package/dist/runtime/internal/route-rules.d.mts +9 -0
  217. package/dist/runtime/internal/route-rules.mjs +72 -0
  218. package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -0
  219. package/dist/runtime/internal/routes/dev-tasks.mjs +25 -0
  220. package/dist/runtime/internal/routes/openapi.d.mts +3 -0
  221. package/dist/runtime/internal/routes/openapi.mjs +94 -0
  222. package/dist/runtime/internal/routes/renderer-template.d.mts +2 -0
  223. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +3 -0
  224. package/dist/runtime/internal/routes/renderer-template.dev.mjs +19 -0
  225. package/dist/runtime/internal/routes/renderer-template.mjs +4 -0
  226. package/dist/runtime/internal/routes/scalar.d.mts +3 -0
  227. package/dist/runtime/internal/routes/scalar.mjs +193 -0
  228. package/dist/runtime/internal/routes/swagger.d.mts +3 -0
  229. package/dist/runtime/internal/routes/swagger.mjs +42 -0
  230. package/dist/runtime/internal/runtime-config.d.mts +9 -0
  231. package/dist/runtime/internal/runtime-config.mjs +54 -0
  232. package/dist/runtime/internal/static.d.mts +3 -0
  233. package/dist/runtime/internal/static.mjs +67 -0
  234. package/dist/runtime/internal/storage.d.mts +2 -0
  235. package/dist/runtime/internal/storage.mjs +6 -0
  236. package/dist/runtime/internal/task.d.mts +19 -0
  237. package/dist/runtime/internal/task.mjs +69 -0
  238. package/dist/runtime/internal/vite/dev-entry.mjs +18 -0
  239. package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
  240. package/dist/runtime/internal/vite/ssr-renderer.mjs +6 -0
  241. package/dist/runtime/meta.d.mts +5 -0
  242. package/dist/runtime/meta.mjs +27 -0
  243. package/dist/runtime/nitro.d.mts +11 -0
  244. package/dist/runtime/nitro.mjs +34 -0
  245. package/dist/runtime/runtime-config.d.mts +1 -0
  246. package/dist/runtime/runtime-config.mjs +1 -0
  247. package/dist/runtime/storage.d.mts +1 -0
  248. package/dist/runtime/storage.mjs +1 -0
  249. package/dist/runtime/task.d.mts +1 -0
  250. package/dist/runtime/task.mjs +1 -0
  251. package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
  252. package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
  253. package/dist/runtime/virtual/database.d.mts +8 -0
  254. package/dist/runtime/virtual/database.mjs +2 -0
  255. package/dist/runtime/virtual/error-handler.d.mts +6 -0
  256. package/dist/runtime/virtual/error-handler.mjs +9 -0
  257. package/dist/runtime/virtual/feature-flags.d.mts +7 -0
  258. package/dist/runtime/virtual/feature-flags.mjs +7 -0
  259. package/dist/runtime/virtual/plugins.d.mts +3 -0
  260. package/dist/runtime/virtual/plugins.mjs +2 -0
  261. package/dist/runtime/virtual/polyfills.d.mts +3 -0
  262. package/dist/runtime/virtual/polyfills.mjs +2 -0
  263. package/dist/runtime/virtual/public-assets.d.mts +9 -0
  264. package/dist/runtime/virtual/public-assets.mjs +8 -0
  265. package/dist/runtime/virtual/renderer-template.d.mts +4 -0
  266. package/dist/runtime/virtual/renderer-template.mjs +7 -0
  267. package/dist/runtime/virtual/routing-meta.d.mts +7 -0
  268. package/dist/runtime/virtual/routing-meta.mjs +2 -0
  269. package/dist/runtime/virtual/routing.d.mts +8 -0
  270. package/dist/runtime/virtual/routing.mjs +11 -0
  271. package/dist/runtime/virtual/runtime-config.d.mts +3 -0
  272. package/dist/runtime/virtual/runtime-config.mjs +5 -0
  273. package/dist/runtime/virtual/server-assets.d.mts +7 -0
  274. package/dist/runtime/virtual/server-assets.mjs +12 -0
  275. package/dist/runtime/virtual/storage.d.mts +3 -0
  276. package/dist/runtime/virtual/storage.mjs +5 -0
  277. package/dist/runtime/virtual/tasks.d.mts +10 -0
  278. package/dist/runtime/virtual/tasks.mjs +3 -0
  279. package/dist/runtime/vite.d.mts +8 -0
  280. package/dist/runtime/vite.mjs +9 -0
  281. package/dist/types/index.d.mts +3010 -0
  282. package/dist/types/index.mjs +1 -0
  283. package/dist/vite.d.mts +52 -0
  284. package/dist/vite.mjs +740 -0
  285. package/lib/h3.d.mts +1 -0
  286. package/lib/h3.mjs +1 -0
  287. package/lib/tsconfig.json +27 -0
  288. package/lib/vite.types.d.mts +26 -0
  289. package/lib/vite.types.mjs +2 -0
  290. package/package.json +256 -0
  291. package/skills/nitro/SKILL.md +10 -0
  292. package/skills/nitro/docs/TOC.md +83 -0
  293. package/skills/nitro/docs/_navigation.json +679 -0
  294. package/skills/nitro/docs/config/index.md +1147 -0
  295. package/skills/nitro/docs/deploy/index.md +64 -0
  296. package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
  297. package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
  298. package/skills/nitro/docs/deploy/providers/aws.md +47 -0
  299. package/skills/nitro/docs/deploy/providers/azure.md +72 -0
  300. package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
  301. package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
  302. package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
  303. package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
  304. package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
  305. package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
  306. package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
  307. package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
  308. package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
  309. package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
  310. package/skills/nitro/docs/deploy/providers/iis.md +38 -0
  311. package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
  312. package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
  313. package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
  314. package/skills/nitro/docs/deploy/providers/render.md +37 -0
  315. package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
  316. package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
  317. package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
  318. package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
  319. package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
  320. package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
  321. package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
  322. package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
  323. package/skills/nitro/docs/docs/assets.md +166 -0
  324. package/skills/nitro/docs/docs/cache.md +408 -0
  325. package/skills/nitro/docs/docs/configuration.md +256 -0
  326. package/skills/nitro/docs/docs/database.md +185 -0
  327. package/skills/nitro/docs/docs/index.md +56 -0
  328. package/skills/nitro/docs/docs/lifecycle.md +204 -0
  329. package/skills/nitro/docs/docs/migration.md +215 -0
  330. package/skills/nitro/docs/docs/nightly.md +31 -0
  331. package/skills/nitro/docs/docs/plugins.md +164 -0
  332. package/skills/nitro/docs/docs/quick-start.md +110 -0
  333. package/skills/nitro/docs/docs/renderer.md +322 -0
  334. package/skills/nitro/docs/docs/routing.md +711 -0
  335. package/skills/nitro/docs/docs/server-entry.md +239 -0
  336. package/skills/nitro/docs/docs/storage.md +261 -0
  337. package/skills/nitro/docs/docs/tasks.md +277 -0
  338. package/skills/nitro/docs/examples/api-routes.md +145 -0
  339. package/skills/nitro/docs/examples/auto-imports.md +93 -0
  340. package/skills/nitro/docs/examples/cached-handler.md +81 -0
  341. package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
  342. package/skills/nitro/docs/examples/database.md +157 -0
  343. package/skills/nitro/docs/examples/elysia.md +70 -0
  344. package/skills/nitro/docs/examples/express.md +78 -0
  345. package/skills/nitro/docs/examples/fastify.md +79 -0
  346. package/skills/nitro/docs/examples/hello-world.md +68 -0
  347. package/skills/nitro/docs/examples/hono.md +74 -0
  348. package/skills/nitro/docs/examples/import-alias.md +100 -0
  349. package/skills/nitro/docs/examples/index.md +3 -0
  350. package/skills/nitro/docs/examples/middleware.md +91 -0
  351. package/skills/nitro/docs/examples/mono-jsx.md +68 -0
  352. package/skills/nitro/docs/examples/nano-jsx.md +70 -0
  353. package/skills/nitro/docs/examples/plugins.md +91 -0
  354. package/skills/nitro/docs/examples/renderer.md +113 -0
  355. package/skills/nitro/docs/examples/runtime-config.md +97 -0
  356. package/skills/nitro/docs/examples/server-fetch.md +87 -0
  357. package/skills/nitro/docs/examples/shiki.md +198 -0
  358. package/skills/nitro/docs/examples/virtual-routes.md +74 -0
  359. package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
  360. package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
  361. package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
  362. package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
  363. package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
  364. package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
  365. package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
  366. package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
  367. package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
  368. package/skills/nitro/docs/examples/vite-trpc.md +335 -0
  369. package/skills/nitro/docs/examples/websocket.md +282 -0
  370. package/skills/nitro/docs/index.md +121 -0
@@ -0,0 +1,671 @@
1
+ import { EventEmitter } from "node:events";
2
+ import { Readable } from "node:stream";
3
+ import http, { request } from "node:http";
4
+ import nodeHTTPS, { request as request$1 } from "node:https";
5
+ //#region node_modules/.pnpm/httpxy@0.3.1/node_modules/httpxy/dist/index.mjs
6
+ const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
7
+ const isSSL = /^https|wss/;
8
+ function setupOutgoing(outgoing, options, req, forward) {
9
+ outgoing.port = options[forward || "target"].port || (isSSL.test(options[forward || "target"].protocol ?? "http") ? 443 : 80);
10
+ for (const e of [
11
+ "host",
12
+ "hostname",
13
+ "socketPath",
14
+ "pfx",
15
+ "key",
16
+ "passphrase",
17
+ "cert",
18
+ "ca",
19
+ "ciphers",
20
+ "secureProtocol"
21
+ ]) outgoing[e] = options[forward || "target"][e];
22
+ outgoing.method = options.method || req.method;
23
+ outgoing.headers = { ...req.headers };
24
+ if (options.headers) outgoing.headers = {
25
+ ...outgoing.headers,
26
+ ...options.headers
27
+ };
28
+ if (options.auth) outgoing.auth = options.auth;
29
+ if (options.ca) outgoing.ca = options.ca;
30
+ if (isSSL.test(options[forward || "target"].protocol ?? "http")) outgoing.rejectUnauthorized = options.secure === void 0 ? true : options.secure;
31
+ outgoing.agent = options.agent || false;
32
+ outgoing.localAddress = options.localAddress;
33
+ if (!outgoing.agent) {
34
+ outgoing.headers = outgoing.headers || {};
35
+ if (typeof outgoing.headers.connection !== "string" || !upgradeHeader.test(outgoing.headers.connection)) outgoing.headers.connection = "close";
36
+ }
37
+ const target = options[forward || "target"];
38
+ const targetPath = target && options.prependPath !== false ? target.pathname || "" : "";
39
+ const reqUrl = req.url || "";
40
+ const qIdx = reqUrl.indexOf("?");
41
+ const reqPath = qIdx === -1 ? reqUrl : reqUrl.slice(0, qIdx);
42
+ const reqSearch = qIdx === -1 ? "" : reqUrl.slice(qIdx);
43
+ const normalizedPath = reqPath ? reqPath[0] === "/" ? reqPath : "/" + reqPath : "/";
44
+ let outgoingPath = options.toProxy ? "/" + reqUrl : normalizedPath + reqSearch;
45
+ outgoingPath = options.ignorePath ? "" : outgoingPath;
46
+ outgoing.path = joinURL(targetPath, outgoingPath);
47
+ if (options.changeOrigin) outgoing.headers.host = requiresPort(outgoing.port, options[forward || "target"].protocol) && !hasPort(outgoing.host) ? outgoing.host + ":" + outgoing.port : outgoing.host ?? void 0;
48
+ return outgoing;
49
+ }
50
+ function joinURL(base, path) {
51
+ if (!base || base === "/") return path || "/";
52
+ if (!path || path === "/") return base || "/";
53
+ const baseHasTrailing = base[base.length - 1] === "/";
54
+ const pathHasLeading = path[0] === "/";
55
+ if (baseHasTrailing && pathHasLeading) return base + path.slice(1);
56
+ if (!baseHasTrailing && !pathHasLeading) return base + "/" + path;
57
+ return base + path;
58
+ }
59
+ function setupSocket(socket) {
60
+ socket.setTimeout(0);
61
+ socket.setNoDelay(true);
62
+ socket.setKeepAlive(true, 0);
63
+ return socket;
64
+ }
65
+ function getPort(req) {
66
+ const res = req.headers.host ? req.headers.host.match(/:(\d+)/) : "";
67
+ if (res) return res[1];
68
+ return hasEncryptedConnection(req) ? "443" : "80";
69
+ }
70
+ function hasEncryptedConnection(req) {
71
+ return Boolean(req.connection.encrypted || req.connection.pair);
72
+ }
73
+ function rewriteCookieProperty(header, config, property) {
74
+ if (Array.isArray(header)) return header.map(function(headerElement) {
75
+ return rewriteCookieProperty(headerElement, config, property);
76
+ });
77
+ return header.replace(new RegExp(String.raw`(;\s*` + property + "=)([^;]+)", "i"), function(match, prefix, previousValue) {
78
+ let newValue;
79
+ if (previousValue in config) newValue = config[previousValue];
80
+ else if ("*" in config) newValue = config["*"];
81
+ else return match;
82
+ return newValue ? prefix + newValue : "";
83
+ });
84
+ }
85
+ function parseAddr(addr) {
86
+ if (typeof addr === "string") {
87
+ if (addr.startsWith("unix:")) return { socketPath: addr.slice(5) };
88
+ const url = new URL(addr);
89
+ return {
90
+ host: url.hostname,
91
+ port: Number(url.port) || (isSSL.test(url.protocol) ? 443 : 80)
92
+ };
93
+ }
94
+ if (!addr.socketPath && !addr.port) throw new Error("ProxyAddr must have either `port` or `socketPath`");
95
+ return addr;
96
+ }
97
+ function hasPort(host) {
98
+ return host ? !!~host.indexOf(":") : false;
99
+ }
100
+ function requiresPort(_port, _protocol) {
101
+ const protocol = _protocol?.split(":")[0];
102
+ const port = +_port;
103
+ if (!port) return false;
104
+ switch (protocol) {
105
+ case "http":
106
+ case "ws": return port !== 80;
107
+ case "https":
108
+ case "wss": return port !== 443;
109
+ case "ftp": return port !== 21;
110
+ case "gopher": return port !== 70;
111
+ case "file": return false;
112
+ }
113
+ return port !== 0;
114
+ }
115
+ function defineProxyMiddleware(m) {
116
+ return m;
117
+ }
118
+ function defineProxyOutgoingMiddleware(m) {
119
+ return m;
120
+ }
121
+ const redirectRegex = /^201|30([1278])$/;
122
+ const webOutgoingMiddleware = [
123
+ defineProxyOutgoingMiddleware((req, res, proxyRes) => {
124
+ if (req.httpVersion === "1.0") delete proxyRes.headers["transfer-encoding"];
125
+ }),
126
+ defineProxyOutgoingMiddleware((req, res, proxyRes) => {
127
+ if (req.httpVersion === "1.0") proxyRes.headers.connection = req.headers.connection || "close";
128
+ else if (req.httpVersion !== "2.0" && !proxyRes.headers.connection) proxyRes.headers.connection = req.headers.connection || "keep-alive";
129
+ }),
130
+ defineProxyOutgoingMiddleware((req, res, proxyRes, options) => {
131
+ if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite) && proxyRes.headers.location && redirectRegex.test(String(proxyRes.statusCode))) {
132
+ const target = options.target instanceof URL ? options.target : new URL(options.target);
133
+ const u = new URL(proxyRes.headers.location);
134
+ if (target.host !== u.host) return;
135
+ if (options.hostRewrite) u.host = options.hostRewrite;
136
+ else if (options.autoRewrite && req.headers.host) u.host = req.headers.host;
137
+ if (options.protocolRewrite) u.protocol = options.protocolRewrite;
138
+ proxyRes.headers.location = u.toString();
139
+ }
140
+ }),
141
+ defineProxyOutgoingMiddleware((req, res, proxyRes, options) => {
142
+ const rewriteCookieDomainConfig = typeof options.cookieDomainRewrite === "string" ? { "*": options.cookieDomainRewrite } : options.cookieDomainRewrite;
143
+ const rewriteCookiePathConfig = typeof options.cookiePathRewrite === "string" ? { "*": options.cookiePathRewrite } : options.cookiePathRewrite;
144
+ const preserveHeaderKeyCase = options.preserveHeaderKeyCase;
145
+ let rawHeaderKeyMap;
146
+ const setHeader = function(key, header) {
147
+ if (header === void 0) return;
148
+ if (rewriteCookieDomainConfig && key.toLowerCase() === "set-cookie") header = rewriteCookieProperty(header, rewriteCookieDomainConfig, "domain");
149
+ if (rewriteCookiePathConfig && key.toLowerCase() === "set-cookie") header = rewriteCookieProperty(header, rewriteCookiePathConfig, "path");
150
+ res.setHeader(String(key).trim(), header);
151
+ };
152
+ if (preserveHeaderKeyCase && proxyRes.rawHeaders !== void 0) {
153
+ rawHeaderKeyMap = {};
154
+ for (let i = 0; i < proxyRes.rawHeaders.length; i += 2) {
155
+ const key = proxyRes.rawHeaders[i];
156
+ rawHeaderKeyMap[key.toLowerCase()] = key;
157
+ }
158
+ }
159
+ for (let key of Object.keys(proxyRes.headers)) {
160
+ const header = proxyRes.headers[key];
161
+ if (preserveHeaderKeyCase && rawHeaderKeyMap) key = rawHeaderKeyMap[key] || key;
162
+ setHeader(key, header);
163
+ }
164
+ }),
165
+ defineProxyOutgoingMiddleware((req, res, proxyRes) => {
166
+ if (proxyRes.statusMessage) {
167
+ res.statusCode = proxyRes.statusCode;
168
+ res.statusMessage = proxyRes.statusMessage;
169
+ } else res.statusCode = proxyRes.statusCode;
170
+ })
171
+ ];
172
+ const nativeAgents = {
173
+ http,
174
+ https: nodeHTTPS
175
+ };
176
+ const redirectStatuses = /* @__PURE__ */ new Set([
177
+ 301,
178
+ 302,
179
+ 303,
180
+ 307,
181
+ 308
182
+ ]);
183
+ const webIncomingMiddleware = [
184
+ defineProxyMiddleware((req) => {
185
+ if ((req.method === "DELETE" || req.method === "OPTIONS") && !req.headers["content-length"]) {
186
+ req.headers["content-length"] = "0";
187
+ delete req.headers["transfer-encoding"];
188
+ }
189
+ }),
190
+ defineProxyMiddleware((req, res, options) => {
191
+ if (options.timeout) req.socket.setTimeout(options.timeout, () => {
192
+ req.socket.destroy();
193
+ });
194
+ }),
195
+ defineProxyMiddleware((req, res, options) => {
196
+ if (!options.xfwd) return;
197
+ const encrypted = req.isSpdy || hasEncryptedConnection(req);
198
+ const values = {
199
+ for: req.connection.remoteAddress || req.socket.remoteAddress,
200
+ port: getPort(req),
201
+ proto: encrypted ? "https" : "http"
202
+ };
203
+ for (const header of [
204
+ "for",
205
+ "port",
206
+ "proto"
207
+ ]) req.headers["x-forwarded-" + header] = (req.headers["x-forwarded-" + header] || "") + (req.headers["x-forwarded-" + header] ? "," : "") + values[header];
208
+ req.headers["x-forwarded-host"] = req.headers["x-forwarded-host"] || req.headers.host || "";
209
+ }),
210
+ defineProxyMiddleware((req, res, options, server, head, callback) => {
211
+ server.emit("start", req, res, options.target || options.forward);
212
+ const http = nativeAgents.http;
213
+ const https = nativeAgents.https;
214
+ const maxRedirects = typeof options.followRedirects === "number" ? options.followRedirects : options.followRedirects ? 5 : 0;
215
+ if (options.forward) {
216
+ const forwardReq = (options.forward.protocol === "https:" ? https : http).request(setupOutgoing(options.ssl || {}, options, req, "forward"));
217
+ const forwardError = createErrorHandler(forwardReq, options.forward);
218
+ req.on("error", forwardError);
219
+ forwardReq.on("error", forwardError);
220
+ (options.buffer || req).pipe(forwardReq);
221
+ if (!options.target) {
222
+ res.end();
223
+ return;
224
+ }
225
+ }
226
+ const proxyReq = (options.target.protocol === "https:" ? https : http).request(setupOutgoing(options.ssl || {}, options, req));
227
+ proxyReq.on("socket", (_socket) => {
228
+ if (server && !proxyReq.getHeader("expect")) server.emit("proxyReq", proxyReq, req, res, options);
229
+ });
230
+ if (options.proxyTimeout) proxyReq.setTimeout(options.proxyTimeout, function() {
231
+ proxyReq.abort();
232
+ });
233
+ req.on("aborted", function() {
234
+ proxyReq.abort();
235
+ });
236
+ res.on("close", function() {
237
+ if (!res.writableFinished) proxyReq.destroy();
238
+ });
239
+ const proxyError = createErrorHandler(proxyReq, options.target);
240
+ req.on("error", proxyError);
241
+ proxyReq.on("error", proxyError);
242
+ function createErrorHandler(proxyReq2, url) {
243
+ return function proxyError2(err) {
244
+ if (req.socket.destroyed && err.code === "ECONNRESET") {
245
+ server.emit("econnreset", err, req, res, url);
246
+ return proxyReq2.abort();
247
+ }
248
+ if (callback) callback(err, req, res, url);
249
+ else server.emit("error", err, req, res, url);
250
+ };
251
+ }
252
+ let bodyBuffer;
253
+ if (maxRedirects > 0) {
254
+ const chunks = [];
255
+ const source = options.buffer || req;
256
+ source.on("data", (chunk) => {
257
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
258
+ proxyReq.write(chunk);
259
+ });
260
+ source.on("end", () => {
261
+ bodyBuffer = Buffer.concat(chunks);
262
+ proxyReq.end();
263
+ });
264
+ source.on("error", (err) => {
265
+ proxyReq.destroy(err);
266
+ });
267
+ } else (options.buffer || req).pipe(proxyReq);
268
+ function handleResponse(proxyRes, redirectCount, currentUrl) {
269
+ const statusCode = proxyRes.statusCode;
270
+ if (maxRedirects > 0 && redirectStatuses.has(statusCode) && redirectCount < maxRedirects && proxyRes.headers.location) {
271
+ proxyRes.resume();
272
+ const location = new URL(proxyRes.headers.location, currentUrl);
273
+ const preserveMethod = statusCode === 307 || statusCode === 308;
274
+ const redirectMethod = preserveMethod ? req.method || "GET" : "GET";
275
+ const isHTTPS = location.protocol === "https:";
276
+ const agent = isHTTPS ? https : http;
277
+ const redirectHeaders = { ...req.headers };
278
+ if (options.headers) Object.assign(redirectHeaders, options.headers);
279
+ redirectHeaders.host = location.host;
280
+ if (location.host !== currentUrl.host) {
281
+ delete redirectHeaders.authorization;
282
+ delete redirectHeaders.cookie;
283
+ }
284
+ if (!preserveMethod) {
285
+ delete redirectHeaders["content-length"];
286
+ delete redirectHeaders["content-type"];
287
+ delete redirectHeaders["transfer-encoding"];
288
+ }
289
+ const redirectOpts = {
290
+ hostname: location.hostname,
291
+ port: location.port || (isHTTPS ? 443 : 80),
292
+ path: location.pathname + location.search,
293
+ method: redirectMethod,
294
+ headers: redirectHeaders,
295
+ agent: options.agent || false
296
+ };
297
+ if (isHTTPS) redirectOpts.rejectUnauthorized = options.secure === void 0 ? true : options.secure;
298
+ const redirectReq = agent.request(redirectOpts);
299
+ if (server && !redirectReq.getHeader("expect")) server.emit("proxyReq", redirectReq, req, res, options);
300
+ if (options.proxyTimeout) redirectReq.setTimeout(options.proxyTimeout, () => {
301
+ redirectReq.abort();
302
+ });
303
+ const redirectError = createErrorHandler(redirectReq, location);
304
+ redirectReq.on("error", redirectError);
305
+ redirectReq.on("response", (nextRes) => {
306
+ handleResponse(nextRes, redirectCount + 1, location);
307
+ });
308
+ if (preserveMethod && bodyBuffer && bodyBuffer.length > 0) redirectReq.end(bodyBuffer);
309
+ else redirectReq.end();
310
+ return;
311
+ }
312
+ if (server) server.emit("proxyRes", proxyRes, req, res);
313
+ if (!res.headersSent && !options.selfHandleResponse) {
314
+ for (const pass of webOutgoingMiddleware) if (pass(req, res, proxyRes, options)) break;
315
+ }
316
+ if (res.finished) {
317
+ if (server) server.emit("end", req, res, proxyRes);
318
+ } else {
319
+ res.on("close", function() {
320
+ proxyRes.destroy();
321
+ });
322
+ proxyRes.on("end", function() {
323
+ if (server) server.emit("end", req, res, proxyRes);
324
+ });
325
+ if (!options.selfHandleResponse) proxyRes.pipe(res);
326
+ }
327
+ }
328
+ proxyReq.on("response", function(proxyRes) {
329
+ handleResponse(proxyRes, 0, options.target);
330
+ });
331
+ })
332
+ ];
333
+ const websocketIncomingMiddleware = [
334
+ defineProxyMiddleware((req, socket) => {
335
+ if (req.method !== "GET" || !req.headers.upgrade) {
336
+ socket.destroy();
337
+ return true;
338
+ }
339
+ if (req.headers.upgrade.toLowerCase() !== "websocket") {
340
+ socket.destroy();
341
+ return true;
342
+ }
343
+ }),
344
+ defineProxyMiddleware((req, socket, options) => {
345
+ if (!options.xfwd) return;
346
+ const values = {
347
+ for: req.connection.remoteAddress || req.socket.remoteAddress,
348
+ port: getPort(req),
349
+ proto: hasEncryptedConnection(req) ? "wss" : "ws"
350
+ };
351
+ for (const header of [
352
+ "for",
353
+ "port",
354
+ "proto"
355
+ ]) req.headers["x-forwarded-" + header] = (req.headers["x-forwarded-" + header] || "") + (req.headers["x-forwarded-" + header] ? "," : "") + values[header];
356
+ }),
357
+ defineProxyMiddleware((req, socket, options, server, head, callback) => {
358
+ const createHttpHeader = function(line, headers) {
359
+ return Object.keys(headers).reduce(function(head2, key) {
360
+ const value = headers[key];
361
+ if (!Array.isArray(value)) {
362
+ head2.push(key + ": " + value);
363
+ return head2;
364
+ }
365
+ for (const element of value) head2.push(key + ": " + element);
366
+ return head2;
367
+ }, [line]).join("\r\n") + "\r\n\r\n";
368
+ };
369
+ setupSocket(socket);
370
+ if (head && head.length > 0) socket.unshift(head);
371
+ socket.on("error", onSocketError);
372
+ const proxyReq = (isSSL.test(options.target.protocol || "http") ? nodeHTTPS : http).request(setupOutgoing(options.ssl || {}, options, req));
373
+ if (server) server.emit("proxyReqWs", proxyReq, req, socket, options, head);
374
+ proxyReq.on("error", onOutgoingError);
375
+ proxyReq.on("response", function(res) {
376
+ if (!res.upgrade) {
377
+ socket.write(createHttpHeader("HTTP/" + res.httpVersion + " " + res.statusCode + " " + res.statusMessage, res.headers));
378
+ res.pipe(socket);
379
+ }
380
+ });
381
+ proxyReq.on("upgrade", function(proxyRes, proxySocket, proxyHead) {
382
+ proxySocket.on("error", onOutgoingError);
383
+ proxySocket.on("end", function() {
384
+ server.emit("close", proxyRes, proxySocket, proxyHead);
385
+ });
386
+ socket.on("error", function() {
387
+ proxySocket.end();
388
+ });
389
+ setupSocket(proxySocket);
390
+ if (proxyHead && proxyHead.length > 0) proxySocket.unshift(proxyHead);
391
+ socket.write(createHttpHeader("HTTP/1.1 101 Switching Protocols", proxyRes.headers));
392
+ proxySocket.pipe(socket).pipe(proxySocket);
393
+ server.emit("open", proxySocket);
394
+ server.emit("proxySocket", proxySocket);
395
+ });
396
+ proxyReq.end();
397
+ function onSocketError(err) {
398
+ if (callback) callback(err, req, socket);
399
+ else server.emit("error", err, req, socket);
400
+ proxyReq.destroy();
401
+ }
402
+ function onOutgoingError(err) {
403
+ if (callback) callback(err, req, socket);
404
+ else server.emit("error", err, req, socket);
405
+ socket.end();
406
+ }
407
+ })
408
+ ];
409
+ var ProxyServer = class extends EventEmitter {
410
+ _server;
411
+ _webPasses = [...webIncomingMiddleware];
412
+ _wsPasses = [...websocketIncomingMiddleware];
413
+ options;
414
+ web;
415
+ ws;
416
+ /**
417
+ * Creates the proxy server with specified options.
418
+ * @param options - Config object passed to the proxy
419
+ */
420
+ constructor(options = {}) {
421
+ super();
422
+ this.options = options || {};
423
+ this.options.prependPath = options.prependPath !== false;
424
+ this.web = _createProxyFn("web", this);
425
+ this.ws = _createProxyFn("ws", this);
426
+ }
427
+ /**
428
+ * A function that wraps the object in a webserver, for your convenience
429
+ * @param port - Port to listen on
430
+ * @param hostname - The hostname to listen on
431
+ */
432
+ listen(port, hostname) {
433
+ const closure = (req, res) => {
434
+ this.web(req, res);
435
+ };
436
+ this._server = this.options.ssl ? nodeHTTPS.createServer(this.options.ssl, closure) : http.createServer(closure);
437
+ if (this.options.ws) this._server.on("upgrade", (req, socket, head) => {
438
+ this.ws(req, socket, head).catch(() => {});
439
+ });
440
+ this._server.listen(port, hostname);
441
+ return this;
442
+ }
443
+ /**
444
+ * A function that closes the inner webserver and stops listening on given port
445
+ */
446
+ close(callback) {
447
+ if (this._server) this._server.close((...args) => {
448
+ this._server = void 0;
449
+ if (callback) Reflect.apply(callback, void 0, args);
450
+ });
451
+ }
452
+ before(type, passName, pass) {
453
+ if (type !== "ws" && type !== "web") throw new Error("type must be `web` or `ws`");
454
+ const passes = this._getPasses(type);
455
+ let i = false;
456
+ for (const [idx, v] of passes.entries()) if (v.name === passName) i = idx;
457
+ if (i === false) throw new Error("No such pass");
458
+ passes.splice(i, 0, pass);
459
+ }
460
+ after(type, passName, pass) {
461
+ if (type !== "ws" && type !== "web") throw new Error("type must be `web` or `ws`");
462
+ const passes = this._getPasses(type);
463
+ let i = false;
464
+ for (const [idx, v] of passes.entries()) if (v.name === passName) i = idx;
465
+ if (i === false) throw new Error("No such pass");
466
+ passes.splice(i++, 0, pass);
467
+ }
468
+ /** @internal */
469
+ _getPasses(type) {
470
+ return type === "ws" ? this._wsPasses : this._webPasses;
471
+ }
472
+ };
473
+ function createProxyServer(options = {}) {
474
+ return new ProxyServer(options);
475
+ }
476
+ function _createProxyFn(type, server) {
477
+ return function(req, res, opts, head) {
478
+ const requestOptions = {
479
+ ...opts,
480
+ ...server.options
481
+ };
482
+ for (const key of ["target", "forward"]) if (typeof requestOptions[key] === "string") requestOptions[key] = new URL(requestOptions[key]);
483
+ if (!requestOptions.target && !requestOptions.forward) {
484
+ this.emit("error", /* @__PURE__ */ new Error("Must provide a proper URL as target"));
485
+ return Promise.resolve();
486
+ }
487
+ let _resolve;
488
+ let _reject;
489
+ const callbackPromise = new Promise((resolve, reject) => {
490
+ _resolve = resolve;
491
+ _reject = reject;
492
+ });
493
+ res.on("close", () => {
494
+ _resolve();
495
+ });
496
+ res.on("error", (error) => {
497
+ _reject(error);
498
+ });
499
+ for (const pass of server._getPasses(type)) if (pass(req, res, requestOptions, server, head, (error) => {
500
+ if (server.listenerCount("error") > 0) {
501
+ server.emit("error", error, req, res);
502
+ _resolve();
503
+ } else _reject(error);
504
+ })) {
505
+ _resolve();
506
+ break;
507
+ }
508
+ return callbackPromise;
509
+ };
510
+ }
511
+ async function proxyFetch(addr, input, inputInit) {
512
+ const resolvedAddr = parseAddr(addr);
513
+ let url;
514
+ let init;
515
+ if (input instanceof Request) {
516
+ url = new URL(input.url);
517
+ init = {
518
+ ...toInit(input),
519
+ ...toInit(inputInit)
520
+ };
521
+ } else {
522
+ url = new URL(input);
523
+ init = toInit(inputInit);
524
+ }
525
+ init = {
526
+ redirect: "manual",
527
+ ...init
528
+ };
529
+ if (init.body) init.duplex = "half";
530
+ const path = url.pathname + url.search;
531
+ const reqHeaders = {};
532
+ if (init.headers) {
533
+ const h = init.headers instanceof Headers ? init.headers : new Headers(init.headers);
534
+ for (const [key, value] of h) reqHeaders[key] = value;
535
+ }
536
+ const res = await new Promise((resolve, reject) => {
537
+ const reqOpts = {
538
+ method: init.method || "GET",
539
+ path,
540
+ headers: reqHeaders
541
+ };
542
+ if (resolvedAddr.socketPath) reqOpts.socketPath = resolvedAddr.socketPath;
543
+ else {
544
+ reqOpts.hostname = resolvedAddr.host || "localhost";
545
+ reqOpts.port = resolvedAddr.port;
546
+ }
547
+ const req = request(reqOpts, resolve);
548
+ req.on("error", reject);
549
+ if (init.body instanceof ReadableStream) {
550
+ const readable = Readable.fromWeb(init.body);
551
+ readable.on("error", reject);
552
+ readable.pipe(req);
553
+ } else if (init.body) req.end(init.body);
554
+ else req.end();
555
+ });
556
+ const headers = new Headers();
557
+ for (const [key, value] of Object.entries(res.headers)) {
558
+ if (key === "transfer-encoding" || key === "keep-alive" || key === "connection") continue;
559
+ if (Array.isArray(value)) for (const v of value) headers.append(key, v);
560
+ else if (value) headers.set(key, value);
561
+ }
562
+ const hasBody = res.statusCode !== 204 && res.statusCode !== 304;
563
+ return new Response(hasBody ? Readable.toWeb(res) : null, {
564
+ status: res.statusCode,
565
+ statusText: res.statusMessage,
566
+ headers
567
+ });
568
+ }
569
+ function toInit(init) {
570
+ if (!init) return;
571
+ if (init instanceof Request) return {
572
+ method: init.method,
573
+ headers: init.headers,
574
+ body: init.body,
575
+ duplex: init.body ? "half" : void 0
576
+ };
577
+ return init;
578
+ }
579
+ function proxyUpgrade(addr, req, socket, head, opts) {
580
+ const resolvedAddr = parseAddr(addr);
581
+ if (req.method !== "GET" || req.headers.upgrade?.toLowerCase() !== "websocket") {
582
+ socket.destroy();
583
+ return Promise.reject(/* @__PURE__ */ new Error("Not a valid WebSocket upgrade request"));
584
+ }
585
+ if (opts?.xfwd !== false) {
586
+ const xfFor = req.headers["x-forwarded-for"];
587
+ const xfPort = req.headers["x-forwarded-port"];
588
+ const xfProto = req.headers["x-forwarded-proto"];
589
+ req.headers["x-forwarded-for"] = `${xfFor ? `${xfFor},` : ""}${req.socket?.remoteAddress}`;
590
+ req.headers["x-forwarded-port"] = `${xfPort ? `${xfPort},` : ""}${getPort(req)}`;
591
+ req.headers["x-forwarded-proto"] = `${xfProto ? `${xfProto},` : ""}${hasEncryptedConnection(req) ? "wss" : "ws"}`;
592
+ }
593
+ const target = _buildTargetURL(resolvedAddr);
594
+ const requestOptions = {
595
+ ...opts,
596
+ target,
597
+ prependPath: opts?.prependPath !== false
598
+ };
599
+ const outgoing = setupOutgoing(requestOptions.ssl || {}, requestOptions, req);
600
+ const sock = socket;
601
+ return new Promise((resolve, reject) => {
602
+ let settled = false;
603
+ setupSocket(sock);
604
+ if (head && head.length > 0) sock.unshift(head);
605
+ sock.once("error", onSocketError);
606
+ const proxyReq = (isSSL.test(target.protocol) ? request$1 : request)(outgoing);
607
+ proxyReq.once("error", onOutgoingError);
608
+ proxyReq.once("response", (res) => {
609
+ if (!res.upgrade) {
610
+ sock.write(_createHttpHeader(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`, res.headers));
611
+ res.pipe(sock);
612
+ if (!settled) {
613
+ settled = true;
614
+ reject(/* @__PURE__ */ new Error("Upstream server did not upgrade the connection"));
615
+ }
616
+ }
617
+ });
618
+ proxyReq.once("upgrade", (proxyRes, proxySocket, proxyHead) => {
619
+ proxySocket.once("error", onOutgoingError);
620
+ sock.removeListener("error", onSocketError);
621
+ sock.once("error", () => {
622
+ proxySocket.end();
623
+ });
624
+ setupSocket(proxySocket);
625
+ if (proxyHead && proxyHead.length > 0) proxySocket.unshift(proxyHead);
626
+ sock.write(_createHttpHeader("HTTP/1.1 101 Switching Protocols", proxyRes.headers));
627
+ proxySocket.pipe(sock).pipe(proxySocket);
628
+ settled = true;
629
+ resolve(proxySocket);
630
+ });
631
+ proxyReq.end();
632
+ function onSocketError(err) {
633
+ proxyReq.destroy();
634
+ if (!settled) {
635
+ settled = true;
636
+ reject(err);
637
+ }
638
+ }
639
+ function onOutgoingError(err) {
640
+ sock.end();
641
+ if (!settled) {
642
+ settled = true;
643
+ reject(err);
644
+ }
645
+ }
646
+ });
647
+ }
648
+ function _buildTargetURL(addr) {
649
+ if (addr.socketPath) {
650
+ const url = new URL("http://unix");
651
+ url.socketPath = addr.socketPath;
652
+ return url;
653
+ }
654
+ return new URL(`http://${addr.host || "localhost"}${addr.port ? `:${addr.port}` : ""}`);
655
+ }
656
+ function _createHttpHeader(line, headers) {
657
+ let result = line;
658
+ for (const key of Object.keys(headers)) {
659
+ const value = headers[key];
660
+ if (value === void 0) continue;
661
+ if (Array.isArray(value)) for (const element of value) result += `\r
662
+ ${key}: ${element}`;
663
+ else result += `\r
664
+ ${key}: ${value}`;
665
+ }
666
+ return `${result}\r
667
+ \r
668
+ `;
669
+ }
670
+ //#endregion
671
+ export { proxyFetch as n, proxyUpgrade as r, createProxyServer as t };
@@ -0,0 +1 @@
1
+ export { };