nitro-nightly 3.0.0-beta-28969273.f7aa9de6 → 4.0.0-20251010-091516-7cafddba
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/README.md +8 -39
- package/dist/_chunks/app.mjs +19797 -0
- package/dist/_chunks/build.mjs +84 -0
- package/dist/_chunks/build2.mjs +318 -0
- package/dist/_chunks/build3.mjs +6452 -0
- package/dist/_chunks/detect-acorn.mjs +503 -0
- package/dist/_chunks/index.mjs +22242 -0
- package/dist/_chunks/index2.mjs +297 -0
- package/dist/_chunks/index3.mjs +1058 -0
- package/dist/_chunks/index4.mjs +1206 -0
- package/dist/_chunks/info.mjs +11157 -0
- package/dist/_chunks/json5.mjs +68 -0
- package/dist/_chunks/jsonc.mjs +51 -0
- package/dist/_chunks/pathe.M-eThtNZ.mjs +204 -0
- package/dist/_chunks/plugin.mjs +960 -0
- package/dist/_chunks/server.mjs +254 -0
- package/dist/_chunks/snapshot.mjs +284 -0
- package/dist/_chunks/toml.mjs +259 -0
- package/dist/_chunks/yaml.mjs +86 -0
- package/dist/cli/build.mjs +10 -3
- package/dist/cli/dev.mjs +41 -9
- package/dist/cli/index.mjs +460 -1
- package/dist/cli/index2.mjs +4 -1
- package/dist/cli/list.mjs +10 -4
- package/dist/cli/prepare.mjs +6 -3
- package/dist/cli/run.mjs +7 -4
- package/dist/index.d.mts +52 -0
- package/dist/index.mjs +55 -0
- package/dist/node_modules/@poppinss/colors/build/index.js +169 -0
- package/dist/node_modules/@poppinss/colors/package.json +116 -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 +717 -0
- package/dist/node_modules/@poppinss/dumper/package.json +122 -0
- package/dist/node_modules/@poppinss/exception/build/index.js +63 -0
- package/dist/node_modules/@poppinss/exception/package.json +106 -0
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +1313 -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 +90 -0
- package/dist/node_modules/cookie/dist/index.js +239 -0
- package/dist/node_modules/cookie/package.json +42 -0
- package/dist/node_modules/croner/dist/croner.js +1 -0
- package/dist/node_modules/croner/package.json +63 -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/hookable/dist/index.mjs +290 -0
- package/dist/node_modules/hookable/package.json +49 -0
- package/dist/node_modules/kleur/index.js +110 -0
- package/dist/node_modules/kleur/index.mjs +110 -0
- package/dist/node_modules/kleur/package.json +51 -0
- package/dist/node_modules/klona/dist/index.mjs +81 -0
- package/dist/node_modules/klona/full/index.mjs +53 -0
- package/dist/node_modules/klona/package.json +74 -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/std-env/dist/index.mjs +1 -0
- package/dist/node_modules/std-env/package.json +46 -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 +638 -0
- package/dist/node_modules/ufo/package.json +47 -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/chunk-4L7RY2JA.js +42 -0
- package/dist/node_modules/youch/build/chunk-4XB2BYKC.js +85 -0
- package/dist/node_modules/youch/build/chunk-4YEN7HVQ.js +61 -0
- package/dist/node_modules/youch/build/chunk-EUJBVOYB.js +83 -0
- package/dist/node_modules/youch/build/chunk-HFSXRSKS.js +85 -0
- package/dist/node_modules/youch/build/chunk-JAN2TFI2.js +222 -0
- package/dist/node_modules/youch/build/chunk-OSUFJZHZ.js +6 -0
- package/dist/node_modules/youch/build/chunk-PINJDICN.js +72 -0
- package/dist/node_modules/youch/build/chunk-PUHGL6HA.js +41 -0
- package/dist/node_modules/youch/build/chunk-VE4LENUR.js +45 -0
- package/dist/node_modules/youch/build/index.js +352 -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 +144 -0
- package/dist/node_modules/youch/build/public/error_stack/script.js +74 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +220 -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 +16 -0
- package/dist/node_modules/youch/build/public/header/style.css +56 -0
- package/dist/node_modules/youch/build/public/layout/script.js +20 -0
- package/dist/node_modules/youch/build/public/layout/style.css +431 -0
- package/dist/node_modules/youch/package.json +133 -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 +48 -73
- package/dist/presets/_nitro/runtime/{nitro-prerenderer.d.ts → nitro-prerenderer.d.mts} +1 -1
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +12 -1
- package/dist/presets/_nitro/runtime/service-worker.mjs +5 -15
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +2 -2
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +18 -0
- package/dist/presets/aws-lambda/runtime/_utils.mjs +102 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +3 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +12 -32
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +3 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +6 -38
- package/dist/{runtime/internal/utils.azure.d.ts → presets/azure/runtime/_utils.d.mts} +1 -1
- package/dist/{runtime/internal/utils.azure.mjs → presets/azure/runtime/_utils.mjs} +3 -4
- package/dist/presets/azure/runtime/azure-swa.mjs +11 -13
- package/dist/presets/bun/runtime/bun.mjs +13 -18
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +13 -0
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +93 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +19 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +74 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +9 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +13 -97
- package/dist/presets/cloudflare/runtime/{cloudflare-pages.d.ts → cloudflare-pages.d.mts} +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +19 -27
- package/dist/{runtime/internal/timing.d.ts → presets/cloudflare/runtime/plugin.dev.d.mts} +1 -0
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +89 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +11 -25
- package/dist/presets/deno/runtime/deno-server.d.mts +6 -0
- package/dist/presets/deno/runtime/deno-server.mjs +15 -21
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +3 -0
- package/dist/presets/netlify/runtime/netlify-edge.mjs +8 -16
- package/dist/presets/netlify/runtime/netlify.mjs +16 -45
- package/dist/presets/node/runtime/{cluster.mjs → node-cluster.mjs} +1 -3
- package/dist/presets/node/runtime/node-middleware.d.mts +4 -0
- package/dist/presets/node/runtime/{node-listener.mjs → node-middleware.mjs} +3 -4
- package/dist/presets/node/runtime/node-server.mjs +3 -4
- package/dist/presets/standard/runtime/server.d.mts +5 -0
- package/dist/presets/standard/runtime/server.mjs +6 -0
- package/dist/presets/stormkit/runtime/stormkit.mjs +8 -12
- package/dist/presets/vercel/runtime/vercel.d.mts +8 -0
- package/dist/presets/vercel/runtime/vercel.mjs +11 -11
- package/dist/presets/winterjs/runtime/winterjs.mjs +22 -4
- package/dist/presets/{node/runtime/node-server.d.ts → zeabur/runtime/zeabur.d.mts} +1 -1
- package/dist/presets/zeabur/runtime/zeabur.mjs +2 -6
- package/dist/presets.mjs +2460 -0
- package/dist/runtime/index.d.mts +11 -0
- package/dist/runtime/index.mjs +8 -8
- package/dist/runtime/internal/app.d.mts +2 -0
- package/dist/runtime/internal/app.mjs +129 -128
- package/dist/runtime/internal/cache.d.mts +7 -0
- package/dist/runtime/internal/cache.mjs +82 -175
- package/dist/runtime/internal/{context.d.ts → context.d.mts} +3 -3
- package/dist/runtime/internal/context.mjs +6 -6
- package/dist/runtime/internal/error/dev.d.mts +9 -0
- package/dist/runtime/internal/error/dev.mjs +122 -0
- package/dist/runtime/internal/error/prod.d.mts +8 -0
- package/dist/runtime/internal/error/prod.mjs +62 -0
- package/dist/runtime/internal/error/utils.d.mts +8 -0
- package/dist/runtime/internal/error/utils.mjs +3 -0
- package/dist/runtime/internal/index.d.mts +3 -0
- package/dist/runtime/internal/index.mjs +1 -14
- package/dist/runtime/internal/renderer.d.mts +3 -0
- package/dist/runtime/internal/renderer.mjs +29 -33
- package/dist/runtime/internal/route-rules.d.mts +8 -0
- package/dist/runtime/internal/route-rules.mjs +58 -63
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -0
- package/dist/runtime/internal/routes/dev-tasks.mjs +23 -0
- package/dist/runtime/internal/routes/openapi.d.mts +3 -0
- package/dist/runtime/internal/routes/openapi.mjs +24 -9
- 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 +21 -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 +7 -4
- package/dist/runtime/internal/routes/swagger.d.mts +3 -0
- package/dist/runtime/internal/routes/swagger.mjs +5 -4
- package/dist/runtime/internal/{utils.env.d.ts → runtime-config.d.mts} +4 -2
- package/dist/runtime/internal/{utils.env.mjs → runtime-config.mjs} +16 -6
- package/dist/runtime/internal/static.d.mts +3 -0
- package/dist/runtime/internal/static.mjs +24 -36
- package/dist/runtime/internal/storage.mjs +2 -1
- package/dist/runtime/internal/task.mjs +6 -6
- package/dist/runtime/internal/utils.d.mts +1 -0
- package/dist/runtime/internal/utils.mjs +1 -116
- package/dist/runtime/internal/vite/dev-entry.d.mts +1 -0
- package/dist/runtime/internal/vite/dev-entry.mjs +6 -0
- package/dist/runtime/internal/vite/dev-worker.mjs +362 -0
- package/dist/runtime/internal/vite/prod-setup.d.mts +4 -0
- package/dist/runtime/internal/vite/prod-setup.mjs +55 -0
- package/dist/runtime/internal/vite/ssr-renderer.d.mts +4 -0
- package/dist/runtime/internal/vite/ssr-renderer.mjs +4 -0
- package/dist/types/index.d.mts +2688 -138
- package/dist/vite.d.mts +59 -0
- package/dist/vite.mjs +68 -0
- package/lib/config.d.mts +9 -0
- package/lib/deps/h3.d.mts +1 -0
- package/lib/deps/h3.mjs +1 -0
- package/lib/deps/ofetch.mjs +1 -0
- package/lib/deps/ofetch.mts +1 -0
- package/lib/meta.d.mts +5 -0
- package/lib/meta.mjs +21 -0
- package/{runtime-meta.d.ts → lib/runtime-meta.d.mts} +1 -0
- package/{runtime-meta.mjs → lib/runtime-meta.mjs} +12 -4
- package/package.json +142 -160
- package/cli.d.ts +0 -1
- package/config.d.ts +0 -1
- package/core.d.ts +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/config/index.d.mts +0 -6
- package/dist/config/index.d.ts +0 -6
- package/dist/core/index.d.mts +0 -30
- package/dist/core/index.d.ts +0 -30
- package/dist/core/index.mjs +0 -2456
- package/dist/kit/index.d.mts +0 -44
- package/dist/kit/index.d.ts +0 -44
- package/dist/kit/index.mjs +0 -71
- package/dist/meta/index.d.mts +0 -3
- package/dist/meta/index.d.ts +0 -3
- package/dist/meta/index.mjs +0 -3
- package/dist/presets/_all.gen.d.ts +0 -2
- package/dist/presets/_all.gen.mjs +0 -52
- package/dist/presets/_nitro/base-worker.d.ts +0 -2
- package/dist/presets/_nitro/base-worker.mjs +0 -25
- package/dist/presets/_nitro/nitro-dev.d.ts +0 -2
- package/dist/presets/_nitro/nitro-dev.mjs +0 -19
- package/dist/presets/_nitro/nitro-prerender.d.ts +0 -2
- package/dist/presets/_nitro/nitro-prerender.mjs +0 -17
- package/dist/presets/_nitro/preset.d.ts +0 -2
- package/dist/presets/_nitro/preset.mjs +0 -5
- package/dist/presets/_nitro/service-worker.d.ts +0 -2
- package/dist/presets/_nitro/service-worker.mjs +0 -110
- package/dist/presets/_resolve.d.ts +0 -8
- package/dist/presets/_resolve.mjs +0 -44
- package/dist/presets/_static/preset.d.ts +0 -2
- package/dist/presets/_static/preset.mjs +0 -69
- package/dist/presets/_types.gen.d.ts +0 -16
- package/dist/presets/alwaysdata/preset.d.ts +0 -2
- package/dist/presets/alwaysdata/preset.mjs +0 -14
- package/dist/presets/aws-amplify/preset.d.ts +0 -3
- package/dist/presets/aws-amplify/preset.mjs +0 -27
- package/dist/presets/aws-amplify/types.d.ts +0 -141
- package/dist/presets/aws-amplify/utils.d.ts +0 -2
- package/dist/presets/aws-amplify/utils.mjs +0 -82
- package/dist/presets/aws-lambda/preset.d.ts +0 -2
- package/dist/presets/aws-lambda/preset.mjs +0 -21
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.ts +0 -14
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.ts +0 -4
- package/dist/presets/azure/preset.d.ts +0 -3
- package/dist/presets/azure/preset.mjs +0 -44
- package/dist/presets/azure/runtime/azure-functions.mjs +0 -24
- package/dist/presets/azure/runtime/azure-swa.d.ts +0 -5
- package/dist/presets/azure/types.d.ts +0 -13
- package/dist/presets/azure/types.mjs +0 -0
- package/dist/presets/azure/utils.d.ts +0 -3
- package/dist/presets/azure/utils.mjs +0 -183
- package/dist/presets/bun/preset.d.ts +0 -2
- package/dist/presets/bun/preset.mjs +0 -17
- package/dist/presets/cleavr/preset.d.ts +0 -2
- package/dist/presets/cleavr/preset.mjs +0 -12
- package/dist/presets/cloudflare/preset.d.ts +0 -3
- package/dist/presets/cloudflare/preset.mjs +0 -145
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.ts +0 -13
- package/dist/presets/cloudflare/runtime/cloudflare-worker.mjs +0 -64
- package/dist/presets/cloudflare/types.d.ts +0 -89
- package/dist/presets/cloudflare/types.mjs +0 -0
- package/dist/presets/cloudflare/types.wrangler.d.ts +0 -974
- package/dist/presets/cloudflare/types.wrangler.mjs +0 -0
- package/dist/presets/cloudflare/utils.d.ts +0 -3
- package/dist/presets/cloudflare/utils.mjs +0 -163
- package/dist/presets/deno/preset.d.ts +0 -2
- package/dist/presets/deno/preset.mjs +0 -148
- package/dist/presets/deno/runtime/_deno-env-polyfill.d.ts +0 -0
- package/dist/presets/deno/runtime/_deno-env-polyfill.mjs +0 -1
- package/dist/presets/digitalocean/preset.d.ts +0 -2
- package/dist/presets/digitalocean/preset.mjs +0 -11
- package/dist/presets/edgio/preset.d.ts +0 -2
- package/dist/presets/edgio/preset.mjs +0 -95
- package/dist/presets/firebase/preset.d.ts +0 -3
- package/dist/presets/firebase/preset.mjs +0 -50
- package/dist/presets/firebase/runtime/firebase-gen-1.d.ts +0 -2
- package/dist/presets/firebase/runtime/firebase-gen-1.mjs +0 -7
- package/dist/presets/firebase/runtime/firebase-gen-2.d.ts +0 -2
- package/dist/presets/firebase/runtime/firebase-gen-2.mjs +0 -14
- package/dist/presets/firebase/runtime/firebase-gen-default.d.ts +0 -1
- package/dist/presets/firebase/runtime/firebase-gen-default.mjs +0 -1
- package/dist/presets/firebase/types.d.ts +0 -38
- package/dist/presets/firebase/types.mjs +0 -0
- package/dist/presets/firebase/utils.d.ts +0 -3
- package/dist/presets/firebase/utils.mjs +0 -50
- package/dist/presets/flightcontrol/preset.d.ts +0 -2
- package/dist/presets/flightcontrol/preset.mjs +0 -11
- package/dist/presets/heroku/preset.d.ts +0 -2
- package/dist/presets/heroku/preset.mjs +0 -11
- package/dist/presets/iis/preset.d.ts +0 -2
- package/dist/presets/iis/preset.mjs +0 -32
- package/dist/presets/iis/utils.d.ts +0 -3
- package/dist/presets/iis/utils.mjs +0 -161
- package/dist/presets/index.d.mts +0 -1
- package/dist/presets/index.d.ts +0 -2
- package/dist/presets/index.mjs +0 -1
- package/dist/presets/koyeb/preset.d.ts +0 -2
- package/dist/presets/koyeb/preset.mjs +0 -11
- package/dist/presets/netlify/legacy/preset.d.ts +0 -2
- package/dist/presets/netlify/legacy/preset.mjs +0 -143
- package/dist/presets/netlify/legacy/runtime/_deno-env-polyfill.d.ts +0 -0
- package/dist/presets/netlify/legacy/runtime/_deno-env-polyfill.mjs +0 -1
- package/dist/presets/netlify/legacy/runtime/netlify-builder.d.ts +0 -3
- package/dist/presets/netlify/legacy/runtime/netlify-builder.mjs +0 -5
- package/dist/presets/netlify/legacy/runtime/netlify-edge.d.ts +0 -2
- package/dist/presets/netlify/legacy/runtime/netlify-edge.mjs +0 -25
- package/dist/presets/netlify/legacy/runtime/netlify-lambda.d.ts +0 -3
- package/dist/presets/netlify/legacy/runtime/netlify-lambda.mjs +0 -38
- package/dist/presets/netlify/legacy/runtime/netlify.d.ts +0 -4
- package/dist/presets/netlify/legacy/runtime/netlify.mjs +0 -22
- package/dist/presets/netlify/legacy/utils.d.ts +0 -4
- package/dist/presets/netlify/legacy/utils.mjs +0 -113
- package/dist/presets/netlify/preset.d.ts +0 -3
- package/dist/presets/netlify/preset.mjs +0 -128
- package/dist/presets/netlify/runtime/_deno-env-polyfill.d.ts +0 -0
- package/dist/presets/netlify/runtime/_deno-env-polyfill.mjs +0 -1
- package/dist/presets/netlify/runtime/netlify-edge.d.ts +0 -2
- package/dist/presets/netlify/types.d.ts +0 -12
- package/dist/presets/netlify/types.mjs +0 -0
- package/dist/presets/netlify/utils.d.ts +0 -5
- package/dist/presets/netlify/utils.mjs +0 -94
- package/dist/presets/node/preset.d.ts +0 -2
- package/dist/presets/node/preset.mjs +0 -49
- package/dist/presets/node/runtime/cli.d.ts +0 -1
- package/dist/presets/node/runtime/cli.mjs +0 -22
- package/dist/presets/node/runtime/node-listener.d.ts +0 -6
- package/dist/presets/platform.sh/preset.d.ts +0 -2
- package/dist/presets/platform.sh/preset.mjs +0 -11
- package/dist/presets/render.com/preset.d.ts +0 -2
- package/dist/presets/render.com/preset.mjs +0 -11
- package/dist/presets/stormkit/preset.d.ts +0 -2
- package/dist/presets/stormkit/preset.mjs +0 -15
- package/dist/presets/vercel/preset.d.ts +0 -3
- package/dist/presets/vercel/preset.mjs +0 -104
- package/dist/presets/vercel/runtime/vercel-edge.d.ts +0 -2
- package/dist/presets/vercel/runtime/vercel-edge.mjs +0 -22
- package/dist/presets/vercel/runtime/vercel.d.ts +0 -4
- package/dist/presets/vercel/types.d.ts +0 -78
- package/dist/presets/vercel/types.mjs +0 -0
- package/dist/presets/vercel/utils.d.ts +0 -5
- package/dist/presets/vercel/utils.mjs +0 -186
- package/dist/presets/winterjs/preset.d.ts +0 -2
- package/dist/presets/winterjs/preset.mjs +0 -20
- package/dist/presets/winterjs/runtime/winterjs.d.ts +0 -1
- package/dist/presets/zeabur/preset.d.ts +0 -2
- package/dist/presets/zeabur/preset.mjs +0 -70
- package/dist/presets/zeabur/runtime/zeabur.d.ts +0 -4
- package/dist/rollup/index.d.mts +0 -5
- package/dist/rollup/index.d.ts +0 -5
- package/dist/rollup/index.mjs +0 -1673
- package/dist/runtime/index.d.ts +0 -12
- package/dist/runtime/internal/app.d.ts +0 -3
- package/dist/runtime/internal/cache.d.ts +0 -8
- package/dist/runtime/internal/client.mjs +0 -4
- package/dist/runtime/internal/config.d.ts +0 -5
- package/dist/runtime/internal/config.mjs +0 -45
- package/dist/runtime/internal/error.d.ts +0 -4
- package/dist/runtime/internal/error.mjs +0 -73
- package/dist/runtime/internal/index.d.ts +0 -6
- package/dist/runtime/internal/renderer.d.ts +0 -2
- package/dist/runtime/internal/route-rules.d.ts +0 -14
- package/dist/runtime/internal/routes/openapi.d.ts +0 -3
- package/dist/runtime/internal/routes/scalar.d.ts +0 -2
- package/dist/runtime/internal/routes/swagger.d.ts +0 -2
- package/dist/runtime/internal/static.d.ts +0 -2
- package/dist/runtime/internal/timing.mjs +0 -29
- package/dist/runtime/internal/utils.d.ts +0 -21
- package/dist/runtime/internal/utils.lambda.d.ts +0 -10
- package/dist/runtime/internal/utils.lambda.mjs +0 -30
- package/dist/shared/nitro.bra5i6ER.d.mts +0 -620
- package/dist/shared/nitro.bra5i6ER.d.ts +0 -620
- package/dist/types/index.d.ts +0 -260
- package/kit.d.ts +0 -1
- package/meta.d.ts +0 -1
- package/presets.d.ts +0 -1
- package/rollup.d.ts +0 -1
- package/runtime.d.ts +0 -1
- package/types.d.ts +0 -1
- /package/dist/presets/_nitro/runtime/{nitro-dev.d.ts → nitro-dev.d.mts} +0 -0
- /package/dist/presets/_nitro/runtime/{service-worker.d.ts → service-worker.d.mts} +0 -0
- /package/dist/presets/aws-amplify/runtime/{aws-amplify.d.ts → aws-amplify.d.mts} +0 -0
- /package/dist/presets/azure/runtime/{azure-functions.d.ts → azure-swa.d.mts} +0 -0
- /package/dist/presets/bun/runtime/{bun.d.ts → bun.d.mts} +0 -0
- /package/dist/presets/{cloudflare/runtime/cloudflare-worker.d.ts → deno/runtime/deno-deploy.d.mts} +0 -0
- /package/dist/presets/netlify/runtime/{netlify.d.ts → netlify.d.mts} +0 -0
- /package/dist/presets/node/runtime/{cluster.d.ts → node-cluster.d.mts} +0 -0
- /package/dist/presets/{deno/runtime/deno-server.d.ts → node/runtime/node-server.d.mts} +0 -0
- /package/dist/presets/stormkit/runtime/{stormkit.d.ts → stormkit.d.mts} +0 -0
- /package/dist/presets/{deno/runtime/deno-deploy.d.ts → winterjs/runtime/winterjs.d.mts} +0 -0
- /package/dist/runtime/internal/{database.d.ts → database.d.mts} +0 -0
- /package/dist/runtime/internal/{debug.d.ts → debug.d.mts} +0 -0
- /package/dist/{presets/_types.gen.mjs → runtime/internal/empty.d.mts} +0 -0
- /package/dist/{presets/aws-amplify/types.mjs → runtime/internal/empty.mjs} +0 -0
- /package/dist/runtime/internal/lib/{http-graceful-shutdown.d.ts → http-graceful-shutdown.d.mts} +0 -0
- /package/dist/runtime/internal/{meta.d.ts → meta.d.mts} +0 -0
- /package/dist/runtime/internal/{plugin.d.ts → plugin.d.mts} +0 -0
- /package/dist/runtime/internal/{shutdown.d.ts → shutdown.d.mts} +0 -0
- /package/dist/runtime/internal/{storage.d.ts → storage.d.mts} +0 -0
- /package/dist/runtime/internal/{task.d.ts → task.d.mts} +0 -0
- /package/dist/runtime/internal/{client.d.ts → vite/dev-worker.d.mts} +0 -0
- /package/{dist/config/index.mjs → lib/config.mjs} +0 -0
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
defineEventHandler,
|
|
4
|
-
fetchWithEvent,
|
|
5
|
-
handleCacheHeaders,
|
|
6
|
-
isEvent,
|
|
7
|
-
splitCookiesString
|
|
8
|
-
} from "h3";
|
|
9
|
-
import { hash } from "ohash";
|
|
1
|
+
import { defineHandler, handleCacheHeaders, isHTTPEvent, toResponse } from "h3";
|
|
2
|
+
import { FastResponse } from "srvx";
|
|
10
3
|
import { parseURL } from "ufo";
|
|
4
|
+
import { hash } from "ohash";
|
|
11
5
|
import { useNitroApp } from "./app.mjs";
|
|
12
6
|
import { useStorage } from "./storage.mjs";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
function defaultCacheOptions() {
|
|
8
|
+
return {
|
|
9
|
+
name: "_",
|
|
10
|
+
base: "/cache",
|
|
11
|
+
swr: true,
|
|
12
|
+
maxAge: 1
|
|
13
|
+
};
|
|
14
|
+
}
|
|
19
15
|
export function defineCachedFunction(fn, opts = {}) {
|
|
20
|
-
opts = { ...defaultCacheOptions, ...opts };
|
|
16
|
+
opts = { ...defaultCacheOptions(), ...opts };
|
|
21
17
|
const pending = {};
|
|
22
18
|
const group = opts.group || "nitro/functions";
|
|
23
19
|
const name = opts.name || fn.name || "_";
|
|
@@ -25,14 +21,17 @@ export function defineCachedFunction(fn, opts = {}) {
|
|
|
25
21
|
const validate = opts.validate || ((entry) => entry.value !== void 0);
|
|
26
22
|
async function get(key, resolver, shouldInvalidateCache, event) {
|
|
27
23
|
const cacheKey = [opts.base, group, name, key + ".json"].filter(Boolean).join(":").replace(/:\/$/, ":index");
|
|
28
|
-
let entry = await useStorage().getItem(cacheKey)
|
|
24
|
+
let entry = await useStorage().getItem(cacheKey).catch((error) => {
|
|
25
|
+
console.error(`[cache] Cache read error.`, error);
|
|
26
|
+
useNitroApp().captureError(error, { event, tags: ["cache"] });
|
|
27
|
+
}) || {};
|
|
29
28
|
if (typeof entry !== "object") {
|
|
30
29
|
entry = {};
|
|
31
30
|
const error = new Error("Malformed data read from cache.");
|
|
32
|
-
console.error("[
|
|
31
|
+
console.error("[cache]", error);
|
|
33
32
|
useNitroApp().captureError(error, { event, tags: ["cache"] });
|
|
34
33
|
}
|
|
35
|
-
const ttl = (opts.maxAge ??
|
|
34
|
+
const ttl = (opts.maxAge ?? 0) * 1e3;
|
|
36
35
|
if (ttl) {
|
|
37
36
|
entry.expires = Date.now() + ttl;
|
|
38
37
|
}
|
|
@@ -61,12 +60,16 @@ export function defineCachedFunction(fn, opts = {}) {
|
|
|
61
60
|
entry.integrity = integrity;
|
|
62
61
|
delete pending[key];
|
|
63
62
|
if (validate(entry) !== false) {
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
let setOpts;
|
|
64
|
+
if (opts.maxAge && !opts.swr) {
|
|
65
|
+
setOpts = { ttl: opts.maxAge };
|
|
66
|
+
}
|
|
67
|
+
const promise = useStorage().setItem(cacheKey, entry, setOpts).catch((error) => {
|
|
68
|
+
console.error(`[cache] Cache write error.`, error);
|
|
66
69
|
useNitroApp().captureError(error, { event, tags: ["cache"] });
|
|
67
70
|
});
|
|
68
|
-
if (event?.waitUntil) {
|
|
69
|
-
event.waitUntil(promise);
|
|
71
|
+
if (typeof event?.req?.waitUntil === "function") {
|
|
72
|
+
event.req.waitUntil(promise);
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
}
|
|
@@ -74,12 +77,12 @@ export function defineCachedFunction(fn, opts = {}) {
|
|
|
74
77
|
const _resolvePromise = expired ? _resolve() : Promise.resolve();
|
|
75
78
|
if (entry.value === void 0) {
|
|
76
79
|
await _resolvePromise;
|
|
77
|
-
} else if (expired && event && event.waitUntil) {
|
|
78
|
-
event.waitUntil(_resolvePromise);
|
|
80
|
+
} else if (expired && event && event.req.waitUntil) {
|
|
81
|
+
event.req.waitUntil(_resolvePromise);
|
|
79
82
|
}
|
|
80
83
|
if (opts.swr && validate(entry) !== false) {
|
|
81
84
|
_resolvePromise.catch((error) => {
|
|
82
|
-
console.error(`[
|
|
85
|
+
console.error(`[cache] SWR handler error.`, error);
|
|
83
86
|
useNitroApp().captureError(error, { event, tags: ["cache"] });
|
|
84
87
|
});
|
|
85
88
|
return entry;
|
|
@@ -97,7 +100,7 @@ export function defineCachedFunction(fn, opts = {}) {
|
|
|
97
100
|
key,
|
|
98
101
|
() => fn(...args),
|
|
99
102
|
shouldInvalidateCache,
|
|
100
|
-
args[0] &&
|
|
103
|
+
args[0] && isHTTPEvent(args[0]) ? args[0] : void 0
|
|
101
104
|
);
|
|
102
105
|
let value = entry.value;
|
|
103
106
|
if (opts.transform) {
|
|
@@ -106,33 +109,43 @@ export function defineCachedFunction(fn, opts = {}) {
|
|
|
106
109
|
return value;
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
|
-
export
|
|
112
|
+
export function cachedFunction(fn, opts = {}) {
|
|
113
|
+
return defineCachedFunction(fn, opts);
|
|
114
|
+
}
|
|
110
115
|
function getKey(...args) {
|
|
111
|
-
return args.length > 0 ? hash(args
|
|
116
|
+
return args.length > 0 ? hash(args) : "";
|
|
112
117
|
}
|
|
113
118
|
function escapeKey(key) {
|
|
114
119
|
return String(key).replace(/\W/g, "");
|
|
115
120
|
}
|
|
116
|
-
export function defineCachedEventHandler(handler, opts = defaultCacheOptions) {
|
|
121
|
+
export function defineCachedEventHandler(handler, opts = defaultCacheOptions()) {
|
|
117
122
|
const variableHeaderNames = (opts.varies || []).filter(Boolean).map((h) => h.toLowerCase()).sort();
|
|
118
123
|
const _opts = {
|
|
119
124
|
...opts,
|
|
125
|
+
shouldBypassCache: (event) => {
|
|
126
|
+
return event.req.method !== "GET" && event.req.method !== "HEAD";
|
|
127
|
+
},
|
|
120
128
|
getKey: async (event) => {
|
|
121
129
|
const customKey = await opts.getKey?.(event);
|
|
122
130
|
if (customKey) {
|
|
123
131
|
return escapeKey(customKey);
|
|
124
132
|
}
|
|
125
|
-
const _path = event.
|
|
126
|
-
|
|
133
|
+
const _path = event.url.pathname + event.url.search;
|
|
134
|
+
let _pathname;
|
|
135
|
+
try {
|
|
136
|
+
_pathname = escapeKey(decodeURI(parseURL(_path).pathname)).slice(0, 16) || "index";
|
|
137
|
+
} catch {
|
|
138
|
+
_pathname = "-";
|
|
139
|
+
}
|
|
127
140
|
const _hashedPath = `${_pathname}.${hash(_path)}`;
|
|
128
|
-
const _headers = variableHeaderNames.map((header) => [header, event.
|
|
141
|
+
const _headers = variableHeaderNames.map((header) => [header, event.req.headers.get(header)]).map(([name, value]) => `${escapeKey(name)}.${hash(value)}`);
|
|
129
142
|
return [_hashedPath, ..._headers].join(":");
|
|
130
143
|
},
|
|
131
144
|
validate: (entry) => {
|
|
132
145
|
if (!entry.value) {
|
|
133
146
|
return false;
|
|
134
147
|
}
|
|
135
|
-
if (entry.value.
|
|
148
|
+
if (entry.value.status >= 400) {
|
|
136
149
|
return false;
|
|
137
150
|
}
|
|
138
151
|
if (entry.value.body === void 0) {
|
|
@@ -147,106 +160,30 @@ export function defineCachedEventHandler(handler, opts = defaultCacheOptions) {
|
|
|
147
160
|
integrity: opts.integrity || hash([handler, opts])
|
|
148
161
|
};
|
|
149
162
|
const _cachedHandler = cachedFunction(
|
|
150
|
-
async (
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
const value = incomingEvent.node.req.headers[header];
|
|
154
|
-
if (value !== void 0) {
|
|
155
|
-
variableHeaders[header] = value;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const reqProxy = cloneWithProxy(incomingEvent.node.req, {
|
|
159
|
-
headers: variableHeaders
|
|
160
|
-
});
|
|
161
|
-
const resHeaders = {};
|
|
162
|
-
let _resSendBody;
|
|
163
|
-
const resProxy = cloneWithProxy(incomingEvent.node.res, {
|
|
164
|
-
statusCode: 200,
|
|
165
|
-
writableEnded: false,
|
|
166
|
-
writableFinished: false,
|
|
167
|
-
headersSent: false,
|
|
168
|
-
closed: false,
|
|
169
|
-
getHeader(name) {
|
|
170
|
-
return resHeaders[name];
|
|
171
|
-
},
|
|
172
|
-
setHeader(name, value) {
|
|
173
|
-
resHeaders[name] = value;
|
|
174
|
-
return this;
|
|
175
|
-
},
|
|
176
|
-
getHeaderNames() {
|
|
177
|
-
return Object.keys(resHeaders);
|
|
178
|
-
},
|
|
179
|
-
hasHeader(name) {
|
|
180
|
-
return name in resHeaders;
|
|
181
|
-
},
|
|
182
|
-
removeHeader(name) {
|
|
183
|
-
delete resHeaders[name];
|
|
184
|
-
},
|
|
185
|
-
getHeaders() {
|
|
186
|
-
return resHeaders;
|
|
187
|
-
},
|
|
188
|
-
end(chunk, arg2, arg3) {
|
|
189
|
-
if (typeof chunk === "string") {
|
|
190
|
-
_resSendBody = chunk;
|
|
191
|
-
}
|
|
192
|
-
if (typeof arg2 === "function") {
|
|
193
|
-
arg2();
|
|
194
|
-
}
|
|
195
|
-
if (typeof arg3 === "function") {
|
|
196
|
-
arg3();
|
|
197
|
-
}
|
|
198
|
-
return this;
|
|
199
|
-
},
|
|
200
|
-
write(chunk, arg2, arg3) {
|
|
201
|
-
if (typeof chunk === "string") {
|
|
202
|
-
_resSendBody = chunk;
|
|
203
|
-
}
|
|
204
|
-
if (typeof arg2 === "function") {
|
|
205
|
-
arg2(void 0);
|
|
206
|
-
}
|
|
207
|
-
if (typeof arg3 === "function") {
|
|
208
|
-
arg3();
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
},
|
|
212
|
-
writeHead(statusCode, headers2) {
|
|
213
|
-
this.statusCode = statusCode;
|
|
214
|
-
if (headers2) {
|
|
215
|
-
if (Array.isArray(headers2) || typeof headers2 === "string") {
|
|
216
|
-
throw new TypeError("Raw headers is not supported.");
|
|
217
|
-
}
|
|
218
|
-
for (const header in headers2) {
|
|
219
|
-
const value = headers2[header];
|
|
220
|
-
if (value !== void 0) {
|
|
221
|
-
this.setHeader(
|
|
222
|
-
header,
|
|
223
|
-
value
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return this;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
const event = createEvent(reqProxy, resProxy);
|
|
232
|
-
event.fetch = (url, fetchOptions) => fetchWithEvent(event, url, fetchOptions, {
|
|
233
|
-
fetch: useNitroApp().localFetch
|
|
234
|
-
});
|
|
235
|
-
event.$fetch = (url, fetchOptions) => fetchWithEvent(event, url, fetchOptions, {
|
|
236
|
-
fetch: globalThis.$fetch
|
|
237
|
-
});
|
|
238
|
-
event.context = incomingEvent.context;
|
|
239
|
-
event.context.cache = {
|
|
240
|
-
options: _opts
|
|
241
|
-
};
|
|
242
|
-
const body = await handler(event) || _resSendBody;
|
|
243
|
-
const headers = event.node.res.getHeaders();
|
|
244
|
-
headers.etag = String(
|
|
245
|
-
headers.Etag || headers.etag || `W/"${hash(body)}"`
|
|
246
|
-
);
|
|
247
|
-
headers["last-modified"] = String(
|
|
248
|
-
headers["Last-Modified"] || headers["last-modified"] || (/* @__PURE__ */ new Date()).toUTCString()
|
|
163
|
+
async (event) => {
|
|
164
|
+
const filteredHeaders = [...event.req.headers.entries()].filter(
|
|
165
|
+
([key]) => !variableHeaderNames.includes(key.toLowerCase())
|
|
249
166
|
);
|
|
167
|
+
try {
|
|
168
|
+
const originalReq = event.req;
|
|
169
|
+
event.req = new Request(event.req.url, {
|
|
170
|
+
method: event.req.method,
|
|
171
|
+
headers: filteredHeaders
|
|
172
|
+
});
|
|
173
|
+
event.req.runtime = originalReq.runtime;
|
|
174
|
+
event.req.waitUntil = originalReq.waitUntil;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.error("[cache] Failed to filter headers:", error);
|
|
177
|
+
}
|
|
178
|
+
const rawValue = await handler(event);
|
|
179
|
+
const res = await toResponse(rawValue, event);
|
|
180
|
+
const body = await res.text();
|
|
181
|
+
if (!res.headers.has("etag")) {
|
|
182
|
+
res.headers.set("etag", `W/"${hash(body)}"`);
|
|
183
|
+
}
|
|
184
|
+
if (!res.headers.has("last-modified")) {
|
|
185
|
+
res.headers.set("last-modified", (/* @__PURE__ */ new Date()).toUTCString());
|
|
186
|
+
}
|
|
250
187
|
const cacheControl = [];
|
|
251
188
|
if (opts.swr) {
|
|
252
189
|
if (opts.maxAge) {
|
|
@@ -261,30 +198,26 @@ export function defineCachedEventHandler(handler, opts = defaultCacheOptions) {
|
|
|
261
198
|
cacheControl.push(`max-age=${opts.maxAge}`);
|
|
262
199
|
}
|
|
263
200
|
if (cacheControl.length > 0) {
|
|
264
|
-
headers
|
|
201
|
+
res.headers.set("cache-control", cacheControl.join(", "));
|
|
265
202
|
}
|
|
266
203
|
const cacheEntry = {
|
|
267
|
-
|
|
268
|
-
|
|
204
|
+
status: res.status,
|
|
205
|
+
statusText: res.statusText,
|
|
206
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
269
207
|
body
|
|
270
208
|
};
|
|
271
209
|
return cacheEntry;
|
|
272
210
|
},
|
|
273
211
|
_opts
|
|
274
212
|
);
|
|
275
|
-
return
|
|
213
|
+
return defineHandler(async (event) => {
|
|
276
214
|
if (opts.headersOnly) {
|
|
277
215
|
if (handleCacheHeaders(event, { maxAge: opts.maxAge })) {
|
|
278
216
|
return;
|
|
279
217
|
}
|
|
280
218
|
return handler(event);
|
|
281
219
|
}
|
|
282
|
-
const response = await _cachedHandler(
|
|
283
|
-
event
|
|
284
|
-
);
|
|
285
|
-
if (event.node.res.headersSent || event.node.res.writableEnded) {
|
|
286
|
-
return response.body;
|
|
287
|
-
}
|
|
220
|
+
const response = await _cachedHandler(event);
|
|
288
221
|
if (handleCacheHeaders(event, {
|
|
289
222
|
modifiedTime: new Date(response.headers["last-modified"]),
|
|
290
223
|
etag: response.headers.etag,
|
|
@@ -292,38 +225,12 @@ export function defineCachedEventHandler(handler, opts = defaultCacheOptions) {
|
|
|
292
225
|
})) {
|
|
293
226
|
return;
|
|
294
227
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
name,
|
|
301
|
-
splitCookiesString(value)
|
|
302
|
-
);
|
|
303
|
-
} else {
|
|
304
|
-
if (value !== void 0) {
|
|
305
|
-
event.node.res.setHeader(name, value);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return response.body;
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
function cloneWithProxy(obj, overrides) {
|
|
313
|
-
return new Proxy(obj, {
|
|
314
|
-
get(target, property, receiver) {
|
|
315
|
-
if (property in overrides) {
|
|
316
|
-
return overrides[property];
|
|
317
|
-
}
|
|
318
|
-
return Reflect.get(target, property, receiver);
|
|
319
|
-
},
|
|
320
|
-
set(target, property, value, receiver) {
|
|
321
|
-
if (property in overrides) {
|
|
322
|
-
overrides[property] = value;
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
return Reflect.set(target, property, value, receiver);
|
|
326
|
-
}
|
|
228
|
+
return new FastResponse(response.body, {
|
|
229
|
+
status: response.status,
|
|
230
|
+
statusText: response.statusText,
|
|
231
|
+
headers: response.headers
|
|
232
|
+
});
|
|
327
233
|
});
|
|
328
234
|
}
|
|
329
235
|
export const cachedEventHandler = defineCachedEventHandler;
|
|
236
|
+
export const defineCachedHandler = defineCachedEventHandler;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ServerRequest } from "srvx";
|
|
2
2
|
export declare const nitroAsyncContext: import("unctx/index").UseContext<NitroAsyncContext>;
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
|
-
* Access to the current Nitro request
|
|
5
|
+
* Access to the current Nitro request.
|
|
6
6
|
*
|
|
7
7
|
* @experimental
|
|
8
8
|
* - Requires `experimental.asyncContext: true` config to work.
|
|
9
9
|
* - Works in Node.js and limited runtimes only
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function useRequest(): ServerRequest;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import {
|
|
2
|
+
import { HTTPError } from "h3";
|
|
3
3
|
import { getContext } from "unctx";
|
|
4
|
-
export const nitroAsyncContext = getContext("nitro-app", {
|
|
4
|
+
export const nitroAsyncContext = /* @__PURE__ */ (() => getContext("nitro-app", {
|
|
5
5
|
asyncContext: import.meta._asyncContext,
|
|
6
6
|
AsyncLocalStorage: import.meta._asyncContext ? AsyncLocalStorage : void 0
|
|
7
|
-
});
|
|
8
|
-
export function
|
|
7
|
+
}))();
|
|
8
|
+
export function useRequest() {
|
|
9
9
|
try {
|
|
10
|
-
return nitroAsyncContext.use().
|
|
10
|
+
return nitroAsyncContext.use().request;
|
|
11
11
|
} catch {
|
|
12
12
|
const hint = import.meta._asyncContext ? "Note: This is an experimental feature and might be broken on non-Node.js environments." : "Enable the experimental flag using `experimental.asyncContext: true`.";
|
|
13
|
-
throw
|
|
13
|
+
throw new HTTPError({
|
|
14
14
|
message: `Nitro request context is not available. ${hint}`
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HTTPError, HTTPEvent } from "h3";
|
|
2
|
+
import type { InternalHandlerResponse } from "./utils.mjs";
|
|
3
|
+
declare const _default: NitroErrorHandler;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare function defaultHandler(error: HTTPError, event: HTTPEvent, opts?: {
|
|
6
|
+
silent?: boolean;
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}): Promise<InternalHandlerResponse>;
|
|
9
|
+
export declare function loadStackTrace(error: any): Promise<void>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { getRequestURL } from "h3";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { resolve, dirname } from "node:path";
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
import { ErrorParser } from "youch-core";
|
|
6
|
+
import { Youch } from "youch";
|
|
7
|
+
import { SourceMapConsumer } from "source-map";
|
|
8
|
+
import { defineNitroErrorHandler } from "./utils.mjs";
|
|
9
|
+
import { FastResponse } from "srvx";
|
|
10
|
+
export default defineNitroErrorHandler(
|
|
11
|
+
async function defaultNitroErrorHandler(error, event) {
|
|
12
|
+
const res = await defaultHandler(error, event);
|
|
13
|
+
return new FastResponse(
|
|
14
|
+
typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2),
|
|
15
|
+
res
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
export async function defaultHandler(error, event, opts) {
|
|
20
|
+
const isSensitive = error.unhandled;
|
|
21
|
+
const status = error.status || 500;
|
|
22
|
+
const url = getRequestURL(event, { xForwardedHost: true, xForwardedProto: true });
|
|
23
|
+
if (status === 404) {
|
|
24
|
+
const baseURL = import.meta.baseURL || "/";
|
|
25
|
+
if (/^\/[^/]/.test(baseURL) && !url.pathname.startsWith(baseURL)) {
|
|
26
|
+
const redirectTo = `${baseURL}${url.pathname.slice(1)}${url.search}`;
|
|
27
|
+
return {
|
|
28
|
+
status: 302,
|
|
29
|
+
statusText: "Found",
|
|
30
|
+
headers: { location: redirectTo },
|
|
31
|
+
body: `Redirecting...`
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
await loadStackTrace(error).catch(consola.error);
|
|
36
|
+
const youch = new Youch();
|
|
37
|
+
if (isSensitive && !opts?.silent) {
|
|
38
|
+
const tags = [error.unhandled && "[unhandled]"].filter(Boolean).join(" ");
|
|
39
|
+
const ansiError = await (await youch.toANSI(error)).replaceAll(process.cwd(), ".");
|
|
40
|
+
consola.error(
|
|
41
|
+
`[request error] ${tags} [${event.req.method}] ${url}
|
|
42
|
+
|
|
43
|
+
`,
|
|
44
|
+
ansiError
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const useJSON = opts?.json || !event.req.headers.get("accept")?.includes("text/html");
|
|
48
|
+
const headers = {
|
|
49
|
+
"content-type": useJSON ? "application/json" : "text/html",
|
|
50
|
+
// Prevent browser from guessing the MIME types of resources.
|
|
51
|
+
"x-content-type-options": "nosniff",
|
|
52
|
+
// Prevent error page from being embedded in an iframe
|
|
53
|
+
"x-frame-options": "DENY",
|
|
54
|
+
// Prevent browsers from sending the Referer header
|
|
55
|
+
"referrer-policy": "no-referrer",
|
|
56
|
+
// Disable the execution of any js
|
|
57
|
+
"content-security-policy": "script-src 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self';"
|
|
58
|
+
};
|
|
59
|
+
if (status === 404 || !event.res.headers.has("cache-control")) {
|
|
60
|
+
headers["cache-control"] = "no-cache";
|
|
61
|
+
}
|
|
62
|
+
const body = useJSON ? {
|
|
63
|
+
error: true,
|
|
64
|
+
url,
|
|
65
|
+
status,
|
|
66
|
+
statusText: error.statusText,
|
|
67
|
+
message: error.message,
|
|
68
|
+
data: error.data,
|
|
69
|
+
stack: error.stack?.split("\n").map((line) => line.trim())
|
|
70
|
+
} : await youch.toHTML(error, {
|
|
71
|
+
request: {
|
|
72
|
+
url: url.href,
|
|
73
|
+
method: event.req.method,
|
|
74
|
+
headers: Object.fromEntries(event.req.headers.entries())
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
status,
|
|
79
|
+
statusText: error.statusText,
|
|
80
|
+
headers,
|
|
81
|
+
body
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export async function loadStackTrace(error) {
|
|
85
|
+
if (!(error instanceof Error)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const parsed = await new ErrorParser().defineSourceLoader(sourceLoader).parse(error);
|
|
89
|
+
const stack = error.message + "\n" + parsed.frames.map((frame) => fmtFrame(frame)).join("\n");
|
|
90
|
+
Object.defineProperty(error, "stack", { value: stack });
|
|
91
|
+
if (error.cause) {
|
|
92
|
+
await loadStackTrace(error.cause).catch(consola.error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function sourceLoader(frame) {
|
|
96
|
+
if (!frame.fileName || frame.fileType !== "fs" || frame.type === "native") {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (frame.type === "app") {
|
|
100
|
+
const rawSourceMap = await readFile(`${frame.fileName}.map`, "utf8").catch(() => {
|
|
101
|
+
});
|
|
102
|
+
if (rawSourceMap) {
|
|
103
|
+
const consumer = await new SourceMapConsumer(rawSourceMap);
|
|
104
|
+
const originalPosition = consumer.originalPositionFor({ line: frame.lineNumber, column: frame.columnNumber });
|
|
105
|
+
if (originalPosition.source && originalPosition.line) {
|
|
106
|
+
frame.fileName = resolve(dirname(frame.fileName), originalPosition.source);
|
|
107
|
+
frame.lineNumber = originalPosition.line;
|
|
108
|
+
frame.columnNumber = originalPosition.column || 0;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const contents = await readFile(frame.fileName, "utf8").catch(() => {
|
|
113
|
+
});
|
|
114
|
+
return contents ? { contents } : void 0;
|
|
115
|
+
}
|
|
116
|
+
function fmtFrame(frame) {
|
|
117
|
+
if (frame.type === "native") {
|
|
118
|
+
return frame.raw;
|
|
119
|
+
}
|
|
120
|
+
const src = `${frame.fileName || ""}:${frame.lineNumber}:${frame.columnNumber})`;
|
|
121
|
+
return frame.functionName ? `at ${frame.functionName} (${src}` : `at ${src}`;
|
|
122
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HTTPError, HTTPEvent } from "h3";
|
|
2
|
+
import type { InternalHandlerResponse } from "./utils.mjs";
|
|
3
|
+
declare const _default: NitroErrorHandler;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare function defaultHandler(error: HTTPError, event: HTTPEvent, opts?: {
|
|
6
|
+
silent?: boolean;
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}): InternalHandlerResponse;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getRequestURL } from "h3";
|
|
2
|
+
import { defineNitroErrorHandler } from "./utils.mjs";
|
|
3
|
+
import { FastResponse } from "srvx";
|
|
4
|
+
export default defineNitroErrorHandler(
|
|
5
|
+
function defaultNitroErrorHandler(error, event) {
|
|
6
|
+
const res = defaultHandler(error, event);
|
|
7
|
+
return new FastResponse(JSON.stringify(res.body, null, 2), res);
|
|
8
|
+
}
|
|
9
|
+
);
|
|
10
|
+
export function defaultHandler(error, event, opts) {
|
|
11
|
+
const isSensitive = error.unhandled;
|
|
12
|
+
const status = error.status || 500;
|
|
13
|
+
const url = getRequestURL(event, { xForwardedHost: true, xForwardedProto: true });
|
|
14
|
+
if (status === 404) {
|
|
15
|
+
const baseURL = import.meta.baseURL || "/";
|
|
16
|
+
if (/^\/[^/]/.test(baseURL) && !url.pathname.startsWith(baseURL)) {
|
|
17
|
+
const redirectTo = `${baseURL}${url.pathname.slice(1)}${url.search}`;
|
|
18
|
+
return {
|
|
19
|
+
status: 302,
|
|
20
|
+
statusText: "Found",
|
|
21
|
+
headers: { location: redirectTo },
|
|
22
|
+
body: `Redirecting...`
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (isSensitive && !opts?.silent) {
|
|
27
|
+
const tags = [error.unhandled && "[unhandled]"].filter(Boolean).join(" ");
|
|
28
|
+
console.error(
|
|
29
|
+
`[request error] ${tags} [${event.req.method}] ${url}
|
|
30
|
+
`,
|
|
31
|
+
error
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const headers = {
|
|
35
|
+
"content-type": "application/json",
|
|
36
|
+
// Prevent browser from guessing the MIME types of resources.
|
|
37
|
+
"x-content-type-options": "nosniff",
|
|
38
|
+
// Prevent error page from being embedded in an iframe
|
|
39
|
+
"x-frame-options": "DENY",
|
|
40
|
+
// Prevent browsers from sending the Referer header
|
|
41
|
+
"referrer-policy": "no-referrer",
|
|
42
|
+
// Disable the execution of any js
|
|
43
|
+
"content-security-policy": "script-src 'none'; frame-ancestors 'none';"
|
|
44
|
+
};
|
|
45
|
+
if (status === 404 || !event.res.headers.has("cache-control")) {
|
|
46
|
+
headers["cache-control"] = "no-cache";
|
|
47
|
+
}
|
|
48
|
+
const body = {
|
|
49
|
+
error: true,
|
|
50
|
+
url: url.href,
|
|
51
|
+
status,
|
|
52
|
+
statusText: error.statusText,
|
|
53
|
+
message: isSensitive ? "Server Error" : error.message,
|
|
54
|
+
data: isSensitive ? void 0 : error.data
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
status,
|
|
58
|
+
statusText: error.statusText,
|
|
59
|
+
headers,
|
|
60
|
+
body
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NitroErrorHandler } from "nitro/types";
|
|
2
|
+
export declare function defineNitroErrorHandler(handler: NitroErrorHandler): NitroErrorHandler;
|
|
3
|
+
export type InternalHandlerResponse = {
|
|
4
|
+
status: number;
|
|
5
|
+
statusText: string | undefined;
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
body: string | Record<string, any>;
|
|
8
|
+
};
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
trapUnhandledNodeErrors,
|
|
3
|
-
normalizeCookieHeader,
|
|
4
|
-
requestHasBody,
|
|
5
|
-
joinHeaders,
|
|
6
|
-
toBuffer
|
|
7
|
-
} from "./utils.mjs";
|
|
8
|
-
export {
|
|
9
|
-
normalizeLambdaIncomingHeaders,
|
|
10
|
-
normalizeLambdaOutgoingHeaders,
|
|
11
|
-
normalizeLambdaOutgoingBody
|
|
12
|
-
} from "./utils.lambda.mjs";
|
|
1
|
+
export { trapUnhandledNodeErrors } from "./utils.mjs";
|
|
13
2
|
export { startScheduleRunner, runCronTasks } from "./task.mjs";
|
|
14
|
-
export { getAzureParsedCookiesFromHeaders } from "./utils.azure.mjs";
|
|
15
3
|
export { getGracefulShutdownConfig, setupGracefulShutdown } from "./shutdown.mjs";
|
|
16
|
-
export { getRouteRulesForPath } from "./route-rules.mjs";
|