@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.
- package/LICENSE +27 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +29361 -0
- package/dist/_build/rolldown.mjs +173 -0
- package/dist/_build/rollup.mjs +194 -0
- package/dist/_build/vite.build.mjs +18 -0
- package/dist/_chunks/nitro.mjs +1159 -0
- package/dist/_chunks/nitro2.mjs +102 -0
- package/dist/_chunks/nitro3.mjs +129 -0
- package/dist/_chunks/utils.mjs +272 -0
- package/dist/_common.mjs +35 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +519 -0
- package/dist/_libs/_.mjs +3 -0
- package/dist/_libs/_2.mjs +2 -0
- package/dist/_libs/_3.mjs +3 -0
- package/dist/_libs/_4.mjs +2 -0
- package/dist/_libs/_5.mjs +3 -0
- package/dist/_libs/_6.mjs +4 -0
- package/dist/_libs/_7.mjs +5 -0
- package/dist/_libs/c12+rc9.mjs +812 -0
- package/dist/_libs/c12+readdirp+chokidar.d.mts +230 -0
- package/dist/_libs/citty.mjs +361 -0
- package/dist/_libs/commondir+is-reference.mjs +1311 -0
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/compatx.mjs +45 -0
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/escape-string-regexp.mjs +7 -0
- package/dist/_libs/estree+pluginutils.d.mts +241 -0
- package/dist/_libs/estree-walker.mjs +184 -0
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +1949 -0
- package/dist/_libs/httpxy.d.mts +82 -0
- package/dist/_libs/httpxy.mjs +671 -0
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +37 -0
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+tinyexec.mjs +845 -0
- package/dist/_libs/perfect-debounce.mjs +88 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-inject.mjs +131 -0
- package/dist/_libs/plugin-json.mjs +34 -0
- package/dist/_libs/pluginutils.mjs +646 -0
- package/dist/_libs/readdirp+chokidar.mjs +1606 -0
- package/dist/_libs/remapping.mjs +115 -0
- package/dist/_libs/resolve-uri+gen-mapping.mjs +442 -0
- package/dist/_libs/rou3.d.mts +44 -0
- package/dist/_libs/rou3.mjs +496 -0
- package/dist/_libs/std-env.d.mts +12 -0
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +813 -0
- package/dist/_libs/ultrahtml.mjs +127 -0
- package/dist/_libs/unimport+unplugin.mjs +1684 -0
- package/dist/_libs/unplugin+unimport.d.mts +423 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +1759 -0
- package/dist/builder.d.mts +64 -0
- package/dist/builder.mjs +15 -0
- package/dist/cli/_chunks/build.mjs +47 -0
- package/dist/cli/_chunks/common.mjs +14 -0
- package/dist/cli/_chunks/deploy.mjs +40 -0
- package/dist/cli/_chunks/dev.mjs +62 -0
- package/dist/cli/_chunks/docs.mjs +30 -0
- package/dist/cli/_chunks/list.mjs +25 -0
- package/dist/cli/_chunks/prepare.mjs +17 -0
- package/dist/cli/_chunks/preview.mjs +51 -0
- package/dist/cli/_chunks/run.mjs +53 -0
- package/dist/cli/_chunks/task.mjs +14 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +22 -0
- package/dist/node_modules/@poppinss/colors/build/index.js +139 -0
- package/dist/node_modules/@poppinss/colors/package.json +118 -0
- package/dist/node_modules/@poppinss/dumper/build/chunk-26HALFTP.js +602 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/console/main.js +441 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +725 -0
- package/dist/node_modules/@poppinss/dumper/package.json +122 -0
- package/dist/node_modules/@poppinss/exception/build/index.js +44 -0
- package/dist/node_modules/@poppinss/exception/package.json +109 -0
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +1354 -0
- package/dist/node_modules/@sindresorhus/is/distribution/utilities.js +3 -0
- package/dist/node_modules/@sindresorhus/is/package.json +81 -0
- package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -0
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -0
- package/dist/node_modules/@speed-highlight/core/package.json +94 -0
- package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
- package/dist/node_modules/cookie-es/package.json +37 -0
- package/dist/node_modules/croner/dist/croner.js +1 -0
- package/dist/node_modules/croner/package.json +73 -0
- package/dist/node_modules/defu/dist/defu.mjs +69 -0
- package/dist/node_modules/defu/package.json +43 -0
- package/dist/node_modules/destr/dist/index.mjs +72 -0
- package/dist/node_modules/destr/package.json +47 -0
- package/dist/node_modules/error-stack-parser-es/dist/index.mjs +38 -0
- package/dist/node_modules/error-stack-parser-es/dist/lite.mjs +167 -0
- package/dist/node_modules/error-stack-parser-es/package.json +83 -0
- package/dist/node_modules/get-port-please/dist/index.mjs +430 -0
- package/dist/node_modules/get-port-please/package.json +39 -0
- package/dist/node_modules/kleur/index.mjs +110 -0
- package/dist/node_modules/kleur/package.json +51 -0
- package/dist/node_modules/rendu/dist/index.mjs +380 -0
- package/dist/node_modules/rendu/package.json +47 -0
- package/dist/node_modules/scule/dist/index.mjs +80 -0
- package/dist/node_modules/scule/package.json +43 -0
- package/dist/node_modules/source-map/lib/array-set.js +100 -0
- package/dist/node_modules/source-map/lib/base64-vlq.js +94 -0
- package/dist/node_modules/source-map/lib/base64.js +19 -0
- package/dist/node_modules/source-map/lib/binary-search.js +113 -0
- package/dist/node_modules/source-map/lib/mapping-list.js +83 -0
- package/dist/node_modules/source-map/lib/mappings.wasm +0 -0
- package/dist/node_modules/source-map/lib/read-wasm.js +27 -0
- package/dist/node_modules/source-map/lib/source-map-consumer.js +1081 -0
- package/dist/node_modules/source-map/lib/source-map-generator.js +439 -0
- package/dist/node_modules/source-map/lib/source-node.js +430 -0
- package/dist/node_modules/source-map/lib/url.js +13 -0
- package/dist/node_modules/source-map/lib/util.js +444 -0
- package/dist/node_modules/source-map/lib/wasm.js +138 -0
- package/dist/node_modules/source-map/package.json +79 -0
- package/dist/node_modules/source-map/source-map.js +10 -0
- package/dist/node_modules/supports-color/index.js +202 -0
- package/dist/node_modules/supports-color/package.json +64 -0
- package/dist/node_modules/ufo/dist/index.mjs +645 -0
- package/dist/node_modules/ufo/package.json +48 -0
- package/dist/node_modules/unctx/dist/index.mjs +131 -0
- package/dist/node_modules/unctx/package.json +67 -0
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +212 -0
- package/dist/node_modules/youch/build/public/error_cause/style.css +5 -0
- package/dist/node_modules/youch/build/public/error_info/script.js +13 -0
- package/dist/node_modules/youch/build/public/error_info/style.css +145 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/script.js +72 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +219 -0
- package/dist/node_modules/youch/build/public/error_stack_source/style.css +123 -0
- package/dist/node_modules/youch/build/public/header/script.js +14 -0
- package/dist/node_modules/youch/build/public/header/style.css +56 -0
- package/dist/node_modules/youch/build/public/layout/script.js +12 -0
- package/dist/node_modules/youch/build/public/layout/style.css +435 -0
- package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
- package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
- package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
- package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
- package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
- package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
- package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
- package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
- package/dist/node_modules/youch/package.json +135 -0
- package/dist/node_modules/youch-core/build/index.js +316 -0
- package/dist/node_modules/youch-core/package.json +124 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +20 -0
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +15 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +23 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +14 -0
- package/dist/presets/aws-lambda/runtime/_utils.mjs +116 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +31 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +13 -0
- package/dist/presets/azure/runtime/_utils.mjs +50 -0
- package/dist/presets/azure/runtime/azure-swa.mjs +30 -0
- package/dist/presets/bun/runtime/bun.mjs +40 -0
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +87 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +72 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +17 -0
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +39 -0
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +96 -0
- package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +19 -0
- package/dist/presets/deno/runtime/deno-server.mjs +39 -0
- package/dist/presets/netlify/runtime/netlify-edge.mjs +20 -0
- package/dist/presets/netlify/runtime/netlify.mjs +20 -0
- package/dist/presets/node/runtime/node-cluster.mjs +54 -0
- package/dist/presets/node/runtime/node-middleware.mjs +14 -0
- package/dist/presets/node/runtime/node-server.mjs +47 -0
- package/dist/presets/standard/runtime/server.mjs +4 -0
- package/dist/presets/stormkit/runtime/stormkit.mjs +27 -0
- package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
- package/dist/presets/vercel/runtime/isr.mjs +19 -0
- package/dist/presets/vercel/runtime/vercel.node.mjs +24 -0
- package/dist/presets/vercel/runtime/vercel.web.mjs +23 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +91 -0
- package/dist/presets/zeabur/runtime/zeabur.mjs +4 -0
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/app.d.mts +1 -0
- package/dist/runtime/app.mjs +1 -0
- package/dist/runtime/cache.d.mts +1 -0
- package/dist/runtime/cache.mjs +1 -0
- package/dist/runtime/config.d.mts +3 -0
- package/dist/runtime/config.mjs +4 -0
- package/dist/runtime/context.d.mts +1 -0
- package/dist/runtime/context.mjs +1 -0
- package/dist/runtime/database.d.mts +1 -0
- package/dist/runtime/database.mjs +1 -0
- package/dist/runtime/internal/app.d.mts +16 -0
- package/dist/runtime/internal/app.mjs +208 -0
- package/dist/runtime/internal/cache.d.mts +7 -0
- package/dist/runtime/internal/cache.mjs +41 -0
- package/dist/runtime/internal/context.d.mts +14 -0
- package/dist/runtime/internal/context.mjs +24 -0
- package/dist/runtime/internal/database.d.mts +2 -0
- package/dist/runtime/internal/database.mjs +12 -0
- package/dist/runtime/internal/empty.mjs +0 -0
- package/dist/runtime/internal/error/dev.d.mts +10 -0
- package/dist/runtime/internal/error/dev.mjs +121 -0
- package/dist/runtime/internal/error/hooks.d.mts +1 -0
- package/dist/runtime/internal/error/hooks.mjs +9 -0
- package/dist/runtime/internal/error/prod.d.mts +6 -0
- package/dist/runtime/internal/error/prod.mjs +40 -0
- package/dist/runtime/internal/error/utils.d.mts +8 -0
- package/dist/runtime/internal/error/utils.mjs +3 -0
- package/dist/runtime/internal/meta.d.mts +2 -0
- package/dist/runtime/internal/meta.mjs +3 -0
- package/dist/runtime/internal/plugin.d.mts +3 -0
- package/dist/runtime/internal/plugin.mjs +4 -0
- package/dist/runtime/internal/route-rules.d.mts +9 -0
- package/dist/runtime/internal/route-rules.mjs +72 -0
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -0
- package/dist/runtime/internal/routes/dev-tasks.mjs +25 -0
- package/dist/runtime/internal/routes/openapi.d.mts +3 -0
- package/dist/runtime/internal/routes/openapi.mjs +94 -0
- package/dist/runtime/internal/routes/renderer-template.d.mts +2 -0
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +3 -0
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +19 -0
- package/dist/runtime/internal/routes/renderer-template.mjs +4 -0
- package/dist/runtime/internal/routes/scalar.d.mts +3 -0
- package/dist/runtime/internal/routes/scalar.mjs +193 -0
- package/dist/runtime/internal/routes/swagger.d.mts +3 -0
- package/dist/runtime/internal/routes/swagger.mjs +42 -0
- package/dist/runtime/internal/runtime-config.d.mts +9 -0
- package/dist/runtime/internal/runtime-config.mjs +54 -0
- package/dist/runtime/internal/static.d.mts +3 -0
- package/dist/runtime/internal/static.mjs +67 -0
- package/dist/runtime/internal/storage.d.mts +2 -0
- package/dist/runtime/internal/storage.mjs +6 -0
- package/dist/runtime/internal/task.d.mts +19 -0
- package/dist/runtime/internal/task.mjs +69 -0
- package/dist/runtime/internal/vite/dev-entry.mjs +18 -0
- package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
- package/dist/runtime/internal/vite/ssr-renderer.mjs +6 -0
- package/dist/runtime/meta.d.mts +5 -0
- package/dist/runtime/meta.mjs +27 -0
- package/dist/runtime/nitro.d.mts +11 -0
- package/dist/runtime/nitro.mjs +34 -0
- package/dist/runtime/runtime-config.d.mts +1 -0
- package/dist/runtime/runtime-config.mjs +1 -0
- package/dist/runtime/storage.d.mts +1 -0
- package/dist/runtime/storage.mjs +1 -0
- package/dist/runtime/task.d.mts +1 -0
- package/dist/runtime/task.mjs +1 -0
- package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
- package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
- package/dist/runtime/virtual/database.d.mts +8 -0
- package/dist/runtime/virtual/database.mjs +2 -0
- package/dist/runtime/virtual/error-handler.d.mts +6 -0
- package/dist/runtime/virtual/error-handler.mjs +9 -0
- package/dist/runtime/virtual/feature-flags.d.mts +7 -0
- package/dist/runtime/virtual/feature-flags.mjs +7 -0
- package/dist/runtime/virtual/plugins.d.mts +3 -0
- package/dist/runtime/virtual/plugins.mjs +2 -0
- package/dist/runtime/virtual/polyfills.d.mts +3 -0
- package/dist/runtime/virtual/polyfills.mjs +2 -0
- package/dist/runtime/virtual/public-assets.d.mts +9 -0
- package/dist/runtime/virtual/public-assets.mjs +8 -0
- package/dist/runtime/virtual/renderer-template.d.mts +4 -0
- package/dist/runtime/virtual/renderer-template.mjs +7 -0
- package/dist/runtime/virtual/routing-meta.d.mts +7 -0
- package/dist/runtime/virtual/routing-meta.mjs +2 -0
- package/dist/runtime/virtual/routing.d.mts +8 -0
- package/dist/runtime/virtual/routing.mjs +11 -0
- package/dist/runtime/virtual/runtime-config.d.mts +3 -0
- package/dist/runtime/virtual/runtime-config.mjs +5 -0
- package/dist/runtime/virtual/server-assets.d.mts +7 -0
- package/dist/runtime/virtual/server-assets.mjs +12 -0
- package/dist/runtime/virtual/storage.d.mts +3 -0
- package/dist/runtime/virtual/storage.mjs +5 -0
- package/dist/runtime/virtual/tasks.d.mts +10 -0
- package/dist/runtime/virtual/tasks.mjs +3 -0
- package/dist/runtime/vite.d.mts +8 -0
- package/dist/runtime/vite.mjs +9 -0
- package/dist/types/index.d.mts +3010 -0
- package/dist/types/index.mjs +1 -0
- package/dist/vite.d.mts +52 -0
- package/dist/vite.mjs +740 -0
- package/lib/h3.d.mts +1 -0
- package/lib/h3.mjs +1 -0
- package/lib/tsconfig.json +27 -0
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +256 -0
- package/skills/nitro/SKILL.md +10 -0
- package/skills/nitro/docs/TOC.md +83 -0
- package/skills/nitro/docs/_navigation.json +679 -0
- package/skills/nitro/docs/config/index.md +1147 -0
- package/skills/nitro/docs/deploy/index.md +64 -0
- package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
- package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
- package/skills/nitro/docs/deploy/providers/aws.md +47 -0
- package/skills/nitro/docs/deploy/providers/azure.md +72 -0
- package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
- package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
- package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
- package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
- package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
- package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
- package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
- package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
- package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
- package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
- package/skills/nitro/docs/deploy/providers/iis.md +38 -0
- package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
- package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
- package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
- package/skills/nitro/docs/deploy/providers/render.md +37 -0
- package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
- package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
- package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
- package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
- package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
- package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
- package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
- package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
- package/skills/nitro/docs/docs/assets.md +166 -0
- package/skills/nitro/docs/docs/cache.md +408 -0
- package/skills/nitro/docs/docs/configuration.md +256 -0
- package/skills/nitro/docs/docs/database.md +185 -0
- package/skills/nitro/docs/docs/index.md +56 -0
- package/skills/nitro/docs/docs/lifecycle.md +204 -0
- package/skills/nitro/docs/docs/migration.md +215 -0
- package/skills/nitro/docs/docs/nightly.md +31 -0
- package/skills/nitro/docs/docs/plugins.md +164 -0
- package/skills/nitro/docs/docs/quick-start.md +110 -0
- package/skills/nitro/docs/docs/renderer.md +322 -0
- package/skills/nitro/docs/docs/routing.md +711 -0
- package/skills/nitro/docs/docs/server-entry.md +239 -0
- package/skills/nitro/docs/docs/storage.md +261 -0
- package/skills/nitro/docs/docs/tasks.md +277 -0
- package/skills/nitro/docs/examples/api-routes.md +145 -0
- package/skills/nitro/docs/examples/auto-imports.md +93 -0
- package/skills/nitro/docs/examples/cached-handler.md +81 -0
- package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
- package/skills/nitro/docs/examples/database.md +157 -0
- package/skills/nitro/docs/examples/elysia.md +70 -0
- package/skills/nitro/docs/examples/express.md +78 -0
- package/skills/nitro/docs/examples/fastify.md +79 -0
- package/skills/nitro/docs/examples/hello-world.md +68 -0
- package/skills/nitro/docs/examples/hono.md +74 -0
- package/skills/nitro/docs/examples/import-alias.md +100 -0
- package/skills/nitro/docs/examples/index.md +3 -0
- package/skills/nitro/docs/examples/middleware.md +91 -0
- package/skills/nitro/docs/examples/mono-jsx.md +68 -0
- package/skills/nitro/docs/examples/nano-jsx.md +70 -0
- package/skills/nitro/docs/examples/plugins.md +91 -0
- package/skills/nitro/docs/examples/renderer.md +113 -0
- package/skills/nitro/docs/examples/runtime-config.md +97 -0
- package/skills/nitro/docs/examples/server-fetch.md +87 -0
- package/skills/nitro/docs/examples/shiki.md +198 -0
- package/skills/nitro/docs/examples/virtual-routes.md +74 -0
- package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
- package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
- package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
- package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
- package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
- package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
- package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
- package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
- package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
- package/skills/nitro/docs/examples/vite-trpc.md +335 -0
- package/skills/nitro/docs/examples/websocket.md +282 -0
- package/skills/nitro/docs/index.md +121 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Middleware
|
|
2
|
+
|
|
3
|
+
> Request middleware for authentication, logging, and request modification.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
serverDir: true,
|
|
12
|
+
});
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```json [package.json]
|
|
16
|
+
{
|
|
17
|
+
"type": "module",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "nitro dev",
|
|
20
|
+
"build": "nitro build"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"nitro": "latest"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts [server.ts]
|
|
29
|
+
import { defineHandler } from "nitro";
|
|
30
|
+
|
|
31
|
+
export default defineHandler((event) => ({
|
|
32
|
+
auth: event.context.auth,
|
|
33
|
+
}));
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```json [tsconfig.json]
|
|
37
|
+
{
|
|
38
|
+
"extends": "nitro/tsconfig"
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```ts [vite.config.ts]
|
|
43
|
+
import { defineConfig } from "vite";
|
|
44
|
+
import { nitro } from "nitro/vite";
|
|
45
|
+
|
|
46
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```ts [server/middleware/auth.ts]
|
|
50
|
+
import { defineMiddleware } from "nitro";
|
|
51
|
+
|
|
52
|
+
export default defineMiddleware((event) => {
|
|
53
|
+
event.context.auth = { name: "User " + Math.round(Math.random() * 100) };
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
</code-tree>
|
|
57
|
+
|
|
58
|
+
Middleware functions run before route handlers on every request. They can modify the request, add context, or return early responses.
|
|
59
|
+
|
|
60
|
+
## Defining Middleware
|
|
61
|
+
|
|
62
|
+
Create files in `server/middleware/`. They run in alphabetical order:
|
|
63
|
+
|
|
64
|
+
```ts [server/middleware/auth.ts]
|
|
65
|
+
import { defineMiddleware } from "nitro";
|
|
66
|
+
|
|
67
|
+
export default defineMiddleware((event) => {
|
|
68
|
+
event.context.auth = { name: "User " + Math.round(Math.random() * 100) };
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Middleware can:
|
|
73
|
+
|
|
74
|
+
- Add data to `event.context` for use in handlers
|
|
75
|
+
- Return a response early to short-circuit the request
|
|
76
|
+
- Modify request headers or other properties
|
|
77
|
+
|
|
78
|
+
## Accessing Context in Handlers
|
|
79
|
+
Data added to `event.context` in middleware is available in all subsequent handlers:
|
|
80
|
+
|
|
81
|
+
```ts [server.ts]
|
|
82
|
+
import { defineHandler } from "nitro";
|
|
83
|
+
|
|
84
|
+
export default defineHandler((event) => ({
|
|
85
|
+
auth: event.context.auth,
|
|
86
|
+
}));
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Learn More
|
|
90
|
+
|
|
91
|
+
- [Routing](/docs/routing)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Mono JSX
|
|
2
|
+
|
|
3
|
+
> Server-side JSX rendering in Nitro with mono-jsx.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```json [package.json]
|
|
14
|
+
{
|
|
15
|
+
"type": "module",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "nitro dev",
|
|
18
|
+
"build": "nitro build"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"mono-jsx": "latest",
|
|
22
|
+
"nitro": "latest"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```tsx [server.tsx]
|
|
28
|
+
export default () => (
|
|
29
|
+
<html>
|
|
30
|
+
<h1>Nitro + mongo-jsx works!</h1>
|
|
31
|
+
</html>
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```json [tsconfig.json]
|
|
36
|
+
{
|
|
37
|
+
"extends": "nitro/tsconfig",
|
|
38
|
+
"compilerOptions": {
|
|
39
|
+
"jsx": "react-jsx",
|
|
40
|
+
"jsxImportSource": "mono-jsx"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```ts [vite.config.ts]
|
|
46
|
+
import { defineConfig } from "vite";
|
|
47
|
+
import { nitro } from "nitro/vite";
|
|
48
|
+
|
|
49
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
50
|
+
```
|
|
51
|
+
</code-tree>
|
|
52
|
+
|
|
53
|
+
## Server Entry
|
|
54
|
+
|
|
55
|
+
```tsx [server.tsx]
|
|
56
|
+
export default () => (
|
|
57
|
+
<html>
|
|
58
|
+
<h1>Nitro + mongo-jsx works!</h1>
|
|
59
|
+
</html>
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Nitro auto-detects `server.tsx` and uses mono-jsx to transform JSX into HTML. Export a function that returns JSX, and Nitro sends the rendered HTML as the response.
|
|
64
|
+
|
|
65
|
+
## Learn More
|
|
66
|
+
|
|
67
|
+
- [Renderer](/docs/renderer)
|
|
68
|
+
- [mono-jsx](https://github.com/aspect-dev/mono-jsx)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Nano JSX
|
|
2
|
+
|
|
3
|
+
> Server-side JSX rendering in Nitro with nano-jsx.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```json [package.json]
|
|
14
|
+
{
|
|
15
|
+
"type": "module",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "nitro dev",
|
|
18
|
+
"build": "nitro build"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"nano-jsx": "^0.2.1",
|
|
22
|
+
"nitro": "latest"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```tsx [server.tsx]
|
|
28
|
+
import { defineHandler, html } from "nitro";
|
|
29
|
+
import { renderSSR } from "nano-jsx";
|
|
30
|
+
|
|
31
|
+
export default defineHandler(() => {
|
|
32
|
+
return html(renderSSR(() => <h1>Nitro + nano-jsx works!</h1>));
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```json [tsconfig.json]
|
|
37
|
+
{
|
|
38
|
+
"extends": "nitro/tsconfig",
|
|
39
|
+
"compilerOptions": {
|
|
40
|
+
"jsx": "react-jsx",
|
|
41
|
+
"jsxImportSource": "nano-jsx/esm"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```ts [vite.config.ts]
|
|
47
|
+
import { defineConfig } from "vite";
|
|
48
|
+
import { nitro } from "nitro/vite";
|
|
49
|
+
|
|
50
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
51
|
+
```
|
|
52
|
+
</code-tree>
|
|
53
|
+
|
|
54
|
+
## Server Entry
|
|
55
|
+
|
|
56
|
+
```tsx [server.tsx]
|
|
57
|
+
import { defineHandler, html } from "nitro";
|
|
58
|
+
import { renderSSR } from "nano-jsx";
|
|
59
|
+
|
|
60
|
+
export default defineHandler(() => {
|
|
61
|
+
return html(renderSSR(() => <h1>Nitro + nano-jsx works!</h1>));
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Nitro auto-detects `server.tsx` and uses it as the server entry. Use `renderSSR` from nano-jsx to convert JSX into an HTML string. The `html` helper from H3 sets the correct content type header.
|
|
66
|
+
|
|
67
|
+
## Learn More
|
|
68
|
+
|
|
69
|
+
- [Renderer](/docs/renderer)
|
|
70
|
+
- [nano-jsx](https://nanojsx.io/)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Plugins
|
|
2
|
+
|
|
3
|
+
> Extend Nitro with custom plugins for hooks and lifecycle events.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
serverDir: true,
|
|
12
|
+
});
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```json [package.json]
|
|
16
|
+
{
|
|
17
|
+
"type": "module",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "nitro dev",
|
|
20
|
+
"build": "nitro build"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"nitro": "latest"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts [server.ts]
|
|
29
|
+
import { eventHandler } from "h3";
|
|
30
|
+
|
|
31
|
+
export default eventHandler(() => "<h1>Hello Nitro!</h1>");
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```json [tsconfig.json]
|
|
35
|
+
{
|
|
36
|
+
"extends": "nitro/tsconfig"
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```ts [vite.config.ts]
|
|
41
|
+
import { defineConfig } from "vite";
|
|
42
|
+
import { nitro } from "nitro/vite";
|
|
43
|
+
|
|
44
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts [server/plugins/test.ts]
|
|
48
|
+
import { definePlugin } from "nitro";
|
|
49
|
+
import { useNitroHooks } from "nitro/app";
|
|
50
|
+
|
|
51
|
+
export default definePlugin((nitroApp) => {
|
|
52
|
+
const hooks = useNitroHooks();
|
|
53
|
+
hooks.hook("response", (event) => {
|
|
54
|
+
event.headers.set("content-type", "html; charset=utf-8");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
</code-tree>
|
|
59
|
+
|
|
60
|
+
Plugins let you hook into Nitro's runtime lifecycle. This example shows a plugin that modifies the `Content-Type` header on every response. Create files in `server/plugins/` and they're automatically loaded at startup.
|
|
61
|
+
|
|
62
|
+
## Defining a Plugin
|
|
63
|
+
|
|
64
|
+
```ts [server/plugins/test.ts]
|
|
65
|
+
import { definePlugin } from "nitro";
|
|
66
|
+
import { useNitroHooks } from "nitro/app";
|
|
67
|
+
|
|
68
|
+
export default definePlugin((nitroApp) => {
|
|
69
|
+
const hooks = useNitroHooks();
|
|
70
|
+
hooks.hook("response", (event) => {
|
|
71
|
+
event.headers.set("content-type", "html; charset=utf-8");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The plugin uses `useNitroHooks()` to access the hooks system, then registers a `response` hook that runs after every request. Here it sets the content type to HTML, but you could log requests, add security headers, or modify responses in any way.
|
|
77
|
+
|
|
78
|
+
## Main Handler
|
|
79
|
+
|
|
80
|
+
```ts [server.ts]
|
|
81
|
+
import { eventHandler } from "h3";
|
|
82
|
+
|
|
83
|
+
export default eventHandler(() => "<h1>Hello Nitro!</h1>");
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The handler returns HTML without setting a content type. The plugin automatically adds the correct `Content-Type: html; charset=utf-8` header to the response.
|
|
87
|
+
|
|
88
|
+
## Learn More
|
|
89
|
+
|
|
90
|
+
- [Plugins](/docs/plugins)
|
|
91
|
+
- [Lifecycle](/docs/lifecycle)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Custom Renderer
|
|
2
|
+
|
|
3
|
+
> Build a custom HTML renderer in Nitro with server-side data fetching.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
serverDir: "./",
|
|
12
|
+
renderer: { handler: "./renderer" },
|
|
13
|
+
});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```json [package.json]
|
|
17
|
+
{
|
|
18
|
+
"type": "module",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "nitro dev",
|
|
21
|
+
"build": "nitro build"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"nitro": "latest"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```ts [renderer.ts]
|
|
30
|
+
import { fetch } from "nitro";
|
|
31
|
+
|
|
32
|
+
export default async function renderer({ url }: { req: Request; url: URL }) {
|
|
33
|
+
const apiRes = await fetch("/api/hello").then((res) => res.text());
|
|
34
|
+
return new Response(
|
|
35
|
+
/* html */ `<!DOCTYPE html>
|
|
36
|
+
<html>
|
|
37
|
+
<head>
|
|
38
|
+
<title>Custom Renderer</title>
|
|
39
|
+
</head>
|
|
40
|
+
<body>
|
|
41
|
+
<h1>Hello from custom renderer!</h1>
|
|
42
|
+
<p>Current path: ${url.pathname}</p>
|
|
43
|
+
<p>API says: ${apiRes}</p>
|
|
44
|
+
</body>
|
|
45
|
+
</html>`,
|
|
46
|
+
{ headers: { "content-type": "text/html; charset=utf-8" } }
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```json [tsconfig.json]
|
|
52
|
+
{
|
|
53
|
+
"extends": "nitro/tsconfig"
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```ts [vite.config.ts]
|
|
58
|
+
import { defineConfig } from "vite";
|
|
59
|
+
import { nitro } from "nitro/vite";
|
|
60
|
+
|
|
61
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```ts [api/hello.ts]
|
|
65
|
+
import { defineHandler } from "nitro";
|
|
66
|
+
|
|
67
|
+
export default defineHandler(() => "Nitro is amazing!");
|
|
68
|
+
```
|
|
69
|
+
</code-tree>
|
|
70
|
+
|
|
71
|
+
Create a custom renderer that generates HTML responses with data from API routes. Use Nitro's internal `fetch` to call routes without network overhead.
|
|
72
|
+
|
|
73
|
+
## Renderer
|
|
74
|
+
|
|
75
|
+
```ts [renderer.ts]
|
|
76
|
+
import { fetch } from "nitro";
|
|
77
|
+
|
|
78
|
+
export default async function renderer({ url }: { req: Request; url: URL }) {
|
|
79
|
+
const apiRes = await fetch("/api/hello").then((res) => res.text());
|
|
80
|
+
return new Response(
|
|
81
|
+
/* html */ `<!DOCTYPE html>
|
|
82
|
+
<html>
|
|
83
|
+
<head>
|
|
84
|
+
<title>Custom Renderer</title>
|
|
85
|
+
</head>
|
|
86
|
+
<body>
|
|
87
|
+
<h1>Hello from custom renderer!</h1>
|
|
88
|
+
<p>Current path: ${url.pathname}</p>
|
|
89
|
+
<p>API says: ${apiRes}</p>
|
|
90
|
+
</body>
|
|
91
|
+
</html>`,
|
|
92
|
+
{ headers: { "content-type": "text/html; charset=utf-8" } }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Nitro auto-detects `renderer.ts` in your project root and uses it for all non-API routes. The renderer function receives the request URL and returns a `Response`.
|
|
98
|
+
|
|
99
|
+
Use `fetch` from `nitro` to call API routes without network overhead—these requests stay in-process.
|
|
100
|
+
|
|
101
|
+
## API Route
|
|
102
|
+
|
|
103
|
+
```ts [api/hello.ts]
|
|
104
|
+
import { defineHandler } from "nitro";
|
|
105
|
+
|
|
106
|
+
export default defineHandler(() => "Nitro is amazing!");
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Define API routes in the `api/` directory. When the renderer calls `fetch("/api/hello")`, this handler runs and returns its response.
|
|
110
|
+
|
|
111
|
+
## Learn More
|
|
112
|
+
|
|
113
|
+
- [Renderer](/docs/renderer)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Runtime Config
|
|
2
|
+
|
|
3
|
+
> Environment-aware configuration with runtime access.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
serverDir: "./",
|
|
12
|
+
runtimeConfig: {
|
|
13
|
+
apiKey: "",
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```json [package.json]
|
|
19
|
+
{
|
|
20
|
+
"type": "module",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "nitro dev",
|
|
23
|
+
"build": "nitro build"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"nitro": "latest"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```ts [server.ts]
|
|
32
|
+
import { defineHandler } from "nitro";
|
|
33
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
34
|
+
|
|
35
|
+
export default defineHandler((event) => {
|
|
36
|
+
const runtimeConfig = useRuntimeConfig();
|
|
37
|
+
return { runtimeConfig };
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```json [tsconfig.json]
|
|
42
|
+
{
|
|
43
|
+
"extends": "nitro/tsconfig"
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts [vite.config.ts]
|
|
48
|
+
import { defineConfig } from "vite";
|
|
49
|
+
import { nitro } from "nitro/vite";
|
|
50
|
+
|
|
51
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
52
|
+
```
|
|
53
|
+
</code-tree>
|
|
54
|
+
|
|
55
|
+
Runtime config lets you define configuration values that can be overridden by environment variables at runtime.
|
|
56
|
+
|
|
57
|
+
## Define Config Schema
|
|
58
|
+
|
|
59
|
+
Declare your runtime config with default values in `nitro.config.ts`:
|
|
60
|
+
|
|
61
|
+
```ts [nitro.config.ts]
|
|
62
|
+
import { defineConfig } from "nitro";
|
|
63
|
+
|
|
64
|
+
export default defineConfig({
|
|
65
|
+
serverDir: "./",
|
|
66
|
+
runtimeConfig: {
|
|
67
|
+
apiKey: "",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Access at Runtime
|
|
73
|
+
|
|
74
|
+
Use `useRuntimeConfig` to access configuration values in your handlers:
|
|
75
|
+
|
|
76
|
+
```ts [server.ts]
|
|
77
|
+
import { defineHandler } from "nitro";
|
|
78
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
79
|
+
|
|
80
|
+
export default defineHandler((event) => {
|
|
81
|
+
const runtimeConfig = useRuntimeConfig();
|
|
82
|
+
return { runtimeConfig };
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Environment Variables
|
|
87
|
+
|
|
88
|
+
Override config values via environment variables prefixed with `NITRO_`:
|
|
89
|
+
|
|
90
|
+
```sh [.env]
|
|
91
|
+
# NEVER COMMIT SENSITIVE DATA. THIS IS ONLY FOR DEMO PURPOSES.
|
|
92
|
+
NITRO_API_KEY=secret-api-key
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Learn More
|
|
96
|
+
|
|
97
|
+
- [Configuration](/docs/configuration)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Server Fetch
|
|
2
|
+
|
|
3
|
+
> Internal server-to-server requests without network overhead.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig, serverFetch } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
serverDir: "./",
|
|
12
|
+
hooks: {
|
|
13
|
+
"dev:start": async () => {
|
|
14
|
+
const res = await serverFetch("/hello");
|
|
15
|
+
const text = await res.text();
|
|
16
|
+
console.log("Fetched /hello in nitro module:", res.status, text);
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```json [package.json]
|
|
23
|
+
{
|
|
24
|
+
"type": "module",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"dev": "nitro dev",
|
|
27
|
+
"build": "nitro build"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"nitro": "latest"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```json [tsconfig.json]
|
|
36
|
+
{
|
|
37
|
+
"extends": "nitro/tsconfig"
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts [vite.config.ts]
|
|
42
|
+
import { defineConfig } from "vite";
|
|
43
|
+
import { nitro } from "nitro/vite";
|
|
44
|
+
|
|
45
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```ts [routes/hello.ts]
|
|
49
|
+
import { defineHandler } from "nitro";
|
|
50
|
+
|
|
51
|
+
export default defineHandler(() => "Hello!");
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```ts [routes/index.ts]
|
|
55
|
+
import { defineHandler } from "nitro";
|
|
56
|
+
import { fetch } from "nitro";
|
|
57
|
+
|
|
58
|
+
export default defineHandler(() => fetch("/hello"));
|
|
59
|
+
```
|
|
60
|
+
</code-tree>
|
|
61
|
+
|
|
62
|
+
When you need one route to call another, use Nitro's `fetch` function instead of the global fetch. It makes internal requests that stay in-process, avoiding network round-trips. The request never leaves the server.
|
|
63
|
+
|
|
64
|
+
## Main Route
|
|
65
|
+
|
|
66
|
+
```ts [routes/index.ts]
|
|
67
|
+
import { defineHandler } from "nitro";
|
|
68
|
+
import { fetch } from "nitro";
|
|
69
|
+
|
|
70
|
+
export default defineHandler(() => fetch("/hello"));
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The index route imports `fetch` from `nitro` (not the global fetch) and calls the `/hello` route. This request is handled internally without going through the network stack.
|
|
74
|
+
|
|
75
|
+
## Internal API Route
|
|
76
|
+
|
|
77
|
+
```ts [routes/hello.ts]
|
|
78
|
+
import { defineHandler } from "nitro";
|
|
79
|
+
|
|
80
|
+
export default defineHandler(() => "Hello!");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
A simple route that returns "Hello!". When the index route calls `fetch("/hello")`, this handler runs and its response is returned directly.
|
|
84
|
+
|
|
85
|
+
## Learn More
|
|
86
|
+
|
|
87
|
+
- [Routing](/docs/routing)
|