@qzsy/vinext 0.1.7
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 +21 -0
- package/README.md +773 -0
- package/dist/build/assets-ignore.d.ts +32 -0
- package/dist/build/assets-ignore.js +48 -0
- package/dist/build/clean-output.d.ts +13 -0
- package/dist/build/clean-output.js +34 -0
- package/dist/build/client-build-config.d.ts +171 -0
- package/dist/build/client-build-config.js +270 -0
- package/dist/build/css-url-assets.d.ts +29 -0
- package/dist/build/css-url-assets.js +213 -0
- package/dist/build/google-fonts/build-url.d.ts +9 -0
- package/dist/build/google-fonts/build-url.js +28 -0
- package/dist/build/google-fonts/fallback-metrics-data.js +14029 -0
- package/dist/build/google-fonts/fallback-metrics.d.ts +12 -0
- package/dist/build/google-fonts/fallback-metrics.js +44 -0
- package/dist/build/google-fonts/find-font-files-in-css.d.ts +16 -0
- package/dist/build/google-fonts/find-font-files-in-css.js +28 -0
- package/dist/build/google-fonts/font-data.js +24983 -0
- package/dist/build/google-fonts/font-metadata.d.ts +16 -0
- package/dist/build/google-fonts/font-metadata.js +5 -0
- package/dist/build/google-fonts/get-axes.d.ts +6 -0
- package/dist/build/google-fonts/get-axes.js +37 -0
- package/dist/build/google-fonts/sort-variants.d.ts +4 -0
- package/dist/build/google-fonts/sort-variants.js +12 -0
- package/dist/build/google-fonts/validate.d.ts +27 -0
- package/dist/build/google-fonts/validate.js +54 -0
- package/dist/build/inline-css.d.ts +6 -0
- package/dist/build/inline-css.js +48 -0
- package/dist/build/layout-classification-types.d.ts +61 -0
- package/dist/build/layout-classification-types.js +1 -0
- package/dist/build/layout-classification.d.ts +59 -0
- package/dist/build/layout-classification.js +98 -0
- package/dist/build/next-client-runtime-manifests.d.ts +14 -0
- package/dist/build/next-client-runtime-manifests.js +39 -0
- package/dist/build/nitro-route-rules.d.ts +49 -0
- package/dist/build/nitro-route-rules.js +79 -0
- package/dist/build/precompress.d.ts +27 -0
- package/dist/build/precompress.js +110 -0
- package/dist/build/prerender.d.ts +209 -0
- package/dist/build/prerender.js +932 -0
- package/dist/build/report.d.ts +132 -0
- package/dist/build/report.js +504 -0
- package/dist/build/route-classification-injector.d.ts +34 -0
- package/dist/build/route-classification-injector.js +59 -0
- package/dist/build/route-classification-manifest.d.ts +52 -0
- package/dist/build/route-classification-manifest.js +143 -0
- package/dist/build/run-prerender.d.ts +61 -0
- package/dist/build/run-prerender.js +224 -0
- package/dist/build/server-manifest.d.ts +18 -0
- package/dist/build/server-manifest.js +22 -0
- package/dist/build/ssr-manifest.d.ts +18 -0
- package/dist/build/ssr-manifest.js +69 -0
- package/dist/build/standalone.d.ts +31 -0
- package/dist/build/standalone.js +203 -0
- package/dist/build/static-export.d.ts +55 -0
- package/dist/build/static-export.js +60 -0
- package/dist/cache/cache-adapters-virtual.d.ts +50 -0
- package/dist/cache/cache-adapters-virtual.js +45 -0
- package/dist/cache.d.ts +2 -0
- package/dist/cache.js +2 -0
- package/dist/check.d.ts +87 -0
- package/dist/check.js +1037 -0
- package/dist/cli-args.d.ts +33 -0
- package/dist/cli-args.js +124 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +744 -0
- package/dist/client/app-nav-failure-handler.d.ts +8 -0
- package/dist/client/app-nav-failure-handler.js +44 -0
- package/dist/client/empty-module.d.ts +1 -0
- package/dist/client/empty-module.js +1 -0
- package/dist/client/instrumentation-client-inject.d.ts +33 -0
- package/dist/client/instrumentation-client-inject.js +55 -0
- package/dist/client/instrumentation-client-state.d.ts +9 -0
- package/dist/client/instrumentation-client-state.js +17 -0
- package/dist/client/instrumentation-client.d.ts +7 -0
- package/dist/client/instrumentation-client.js +6 -0
- package/dist/client/navigation-runtime.d.ts +70 -0
- package/dist/client/navigation-runtime.js +169 -0
- package/dist/client/pages-router-link-navigation.d.ts +61 -0
- package/dist/client/pages-router-link-navigation.js +42 -0
- package/dist/client/validate-module-path.d.ts +17 -0
- package/dist/client/validate-module-path.js +24 -0
- package/dist/client/vinext-next-data.d.ts +44 -0
- package/dist/client/vinext-next-data.js +50 -0
- package/dist/client/window-next.d.ts +168 -0
- package/dist/client/window-next.js +57 -0
- package/dist/cloudflare/index.d.ts +3 -0
- package/dist/cloudflare/index.js +3 -0
- package/dist/cloudflare/src/cache/cdn-adapter.runtime.js +102 -0
- package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +126 -0
- package/dist/cloudflare/src/cache/kv-data-adapter.runtime.js +435 -0
- package/dist/cloudflare/src/utils/cache-control-metadata.js +20 -0
- package/dist/cloudflare/tpr.d.ts +82 -0
- package/dist/cloudflare/tpr.js +558 -0
- package/dist/config/config-matchers.d.ts +257 -0
- package/dist/config/config-matchers.js +1046 -0
- package/dist/config/dotenv.d.ts +56 -0
- package/dist/config/dotenv.js +88 -0
- package/dist/config/next-config.d.ts +540 -0
- package/dist/config/next-config.js +1050 -0
- package/dist/config/tsconfig-paths.d.ts +21 -0
- package/dist/config/tsconfig-paths.js +157 -0
- package/dist/deploy.d.ts +190 -0
- package/dist/deploy.js +1033 -0
- package/dist/entries/app-browser-entry.d.ts +29 -0
- package/dist/entries/app-browser-entry.js +83 -0
- package/dist/entries/app-rsc-entry.d.ts +81 -0
- package/dist/entries/app-rsc-entry.js +943 -0
- package/dist/entries/app-rsc-manifest.d.ts +53 -0
- package/dist/entries/app-rsc-manifest.js +294 -0
- package/dist/entries/app-ssr-entry.d.ts +15 -0
- package/dist/entries/app-ssr-entry.js +24 -0
- package/dist/entries/pages-client-entry.d.ts +11 -0
- package/dist/entries/pages-client-entry.js +204 -0
- package/dist/entries/pages-entry-helpers.d.ts +2 -0
- package/dist/entries/pages-entry-helpers.js +2 -0
- package/dist/entries/pages-server-entry.d.ts +11 -0
- package/dist/entries/pages-server-entry.js +398 -0
- package/dist/entries/runtime-entry-module.d.ts +25 -0
- package/dist/entries/runtime-entry-module.js +46 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +2661 -0
- package/dist/init.d.ts +69 -0
- package/dist/init.js +253 -0
- package/dist/plugins/ast-utils.d.ts +20 -0
- package/dist/plugins/ast-utils.js +78 -0
- package/dist/plugins/async-hooks-stub.d.ts +18 -0
- package/dist/plugins/async-hooks-stub.js +40 -0
- package/dist/plugins/client-reference-dedup.d.ts +35 -0
- package/dist/plugins/client-reference-dedup.js +189 -0
- package/dist/plugins/css-data-url.d.ts +6 -0
- package/dist/plugins/css-data-url.js +83 -0
- package/dist/plugins/dynamic-preload-metadata.d.ts +13 -0
- package/dist/plugins/dynamic-preload-metadata.js +413 -0
- package/dist/plugins/extensionless-dynamic-import.d.ts +6 -0
- package/dist/plugins/extensionless-dynamic-import.js +155 -0
- package/dist/plugins/fonts.d.ts +95 -0
- package/dist/plugins/fonts.js +711 -0
- package/dist/plugins/import-meta-url.d.ts +16 -0
- package/dist/plugins/import-meta-url.js +353 -0
- package/dist/plugins/instrumentation-client.d.ts +6 -0
- package/dist/plugins/instrumentation-client.js +27 -0
- package/dist/plugins/middleware-export-validation.d.ts +5 -0
- package/dist/plugins/middleware-export-validation.js +36 -0
- package/dist/plugins/middleware-server-only.d.ts +53 -0
- package/dist/plugins/middleware-server-only.js +90 -0
- package/dist/plugins/og-asset-ownership.d.ts +27 -0
- package/dist/plugins/og-asset-ownership.js +285 -0
- package/dist/plugins/og-assets.d.ts +50 -0
- package/dist/plugins/og-assets.js +229 -0
- package/dist/plugins/optimize-imports.d.ts +42 -0
- package/dist/plugins/optimize-imports.js +587 -0
- package/dist/plugins/postcss.d.ts +26 -0
- package/dist/plugins/postcss.js +96 -0
- package/dist/plugins/remove-console.d.ts +21 -0
- package/dist/plugins/remove-console.js +177 -0
- package/dist/plugins/require-context.d.ts +6 -0
- package/dist/plugins/require-context.js +185 -0
- package/dist/plugins/rsc-client-reference-loaders.d.ts +6 -0
- package/dist/plugins/rsc-client-reference-loaders.js +46 -0
- package/dist/plugins/rsc-client-shim-excludes.d.ts +6 -0
- package/dist/plugins/rsc-client-shim-excludes.js +35 -0
- package/dist/plugins/sass.d.ts +62 -0
- package/dist/plugins/sass.js +268 -0
- package/dist/plugins/server-externals-manifest.d.ts +26 -0
- package/dist/plugins/server-externals-manifest.js +81 -0
- package/dist/plugins/strip-server-exports.d.ts +21 -0
- package/dist/plugins/strip-server-exports.js +519 -0
- package/dist/plugins/typeof-window.d.ts +14 -0
- package/dist/plugins/typeof-window.js +150 -0
- package/dist/plugins/wasm-module-import.d.ts +15 -0
- package/dist/plugins/wasm-module-import.js +50 -0
- package/dist/routing/app-route-graph.d.ts +336 -0
- package/dist/routing/app-route-graph.js +1518 -0
- package/dist/routing/app-router.d.ts +30 -0
- package/dist/routing/app-router.js +59 -0
- package/dist/routing/file-matcher.d.ts +60 -0
- package/dist/routing/file-matcher.js +147 -0
- package/dist/routing/pages-router.d.ts +48 -0
- package/dist/routing/pages-router.js +163 -0
- package/dist/routing/route-matching.d.ts +27 -0
- package/dist/routing/route-matching.js +42 -0
- package/dist/routing/route-pattern.d.ts +64 -0
- package/dist/routing/route-pattern.js +165 -0
- package/dist/routing/route-trie.d.ts +67 -0
- package/dist/routing/route-trie.js +143 -0
- package/dist/routing/route-validation.d.ts +10 -0
- package/dist/routing/route-validation.js +101 -0
- package/dist/routing/utils.d.ts +117 -0
- package/dist/routing/utils.js +242 -0
- package/dist/server/accept-encoding.d.ts +29 -0
- package/dist/server/accept-encoding.js +95 -0
- package/dist/server/api-handler.d.ts +17 -0
- package/dist/server/api-handler.js +276 -0
- package/dist/server/app-action-request.d.ts +4 -0
- package/dist/server/app-action-request.js +9 -0
- package/dist/server/app-bfcache-id.d.ts +5 -0
- package/dist/server/app-bfcache-id.js +5 -0
- package/dist/server/app-bfcache-identity.d.ts +36 -0
- package/dist/server/app-bfcache-identity.js +156 -0
- package/dist/server/app-browser-action-result.d.ts +64 -0
- package/dist/server/app-browser-action-result.js +111 -0
- package/dist/server/app-browser-client-reuse-manifest.d.ts +12 -0
- package/dist/server/app-browser-client-reuse-manifest.js +101 -0
- package/dist/server/app-browser-entry.d.ts +1 -0
- package/dist/server/app-browser-entry.js +1087 -0
- package/dist/server/app-browser-error.d.ts +13 -0
- package/dist/server/app-browser-error.js +52 -0
- package/dist/server/app-browser-history-controller.d.ts +104 -0
- package/dist/server/app-browser-history-controller.js +210 -0
- package/dist/server/app-browser-hydration.d.ts +32 -0
- package/dist/server/app-browser-hydration.js +29 -0
- package/dist/server/app-browser-interception-context.d.ts +24 -0
- package/dist/server/app-browser-interception-context.js +43 -0
- package/dist/server/app-browser-mpa-navigation.d.ts +16 -0
- package/dist/server/app-browser-mpa-navigation.js +42 -0
- package/dist/server/app-browser-navigation-controller.d.ts +109 -0
- package/dist/server/app-browser-navigation-controller.js +465 -0
- package/dist/server/app-browser-popstate.d.ts +26 -0
- package/dist/server/app-browser-popstate.js +44 -0
- package/dist/server/app-browser-rsc-redirect.d.ts +38 -0
- package/dist/server/app-browser-rsc-redirect.js +64 -0
- package/dist/server/app-browser-server-action-client.d.ts +32 -0
- package/dist/server/app-browser-server-action-client.js +128 -0
- package/dist/server/app-browser-server-action-navigation.d.ts +6 -0
- package/dist/server/app-browser-server-action-navigation.js +9 -0
- package/dist/server/app-browser-state.d.ts +140 -0
- package/dist/server/app-browser-state.js +315 -0
- package/dist/server/app-browser-stream.d.ts +28 -0
- package/dist/server/app-browser-stream.js +122 -0
- package/dist/server/app-browser-visible-commit.d.ts +78 -0
- package/dist/server/app-browser-visible-commit.js +241 -0
- package/dist/server/app-client-reference-preloader.d.ts +14 -0
- package/dist/server/app-client-reference-preloader.js +44 -0
- package/dist/server/app-elements-wire.d.ts +192 -0
- package/dist/server/app-elements-wire.js +443 -0
- package/dist/server/app-elements.d.ts +9 -0
- package/dist/server/app-elements.js +18 -0
- package/dist/server/app-fallback-renderer.d.ts +89 -0
- package/dist/server/app-fallback-renderer.js +136 -0
- package/dist/server/app-history-state.d.ts +85 -0
- package/dist/server/app-history-state.js +223 -0
- package/dist/server/app-hook-warning-suppression.d.ts +6 -0
- package/dist/server/app-hook-warning-suppression.js +10 -0
- package/dist/server/app-inline-css-client.d.ts +6 -0
- package/dist/server/app-inline-css-client.js +35 -0
- package/dist/server/app-interception-context-header.d.ts +32 -0
- package/dist/server/app-interception-context-header.js +42 -0
- package/dist/server/app-layout-param-observation.d.ts +43 -0
- package/dist/server/app-layout-param-observation.js +168 -0
- package/dist/server/app-middleware.d.ts +46 -0
- package/dist/server/app-middleware.js +168 -0
- package/dist/server/app-mounted-slots-header.d.ts +35 -0
- package/dist/server/app-mounted-slots-header.js +58 -0
- package/dist/server/app-optimistic-routing.d.ts +53 -0
- package/dist/server/app-optimistic-routing.js +227 -0
- package/dist/server/app-page-boundary-render.d.ts +85 -0
- package/dist/server/app-page-boundary-render.js +305 -0
- package/dist/server/app-page-boundary.d.ts +102 -0
- package/dist/server/app-page-boundary.js +120 -0
- package/dist/server/app-page-cache-finalizer.d.ts +62 -0
- package/dist/server/app-page-cache-finalizer.js +122 -0
- package/dist/server/app-page-cache-render.d.ts +53 -0
- package/dist/server/app-page-cache-render.js +91 -0
- package/dist/server/app-page-cache.d.ts +83 -0
- package/dist/server/app-page-cache.js +272 -0
- package/dist/server/app-page-dispatch.d.ts +223 -0
- package/dist/server/app-page-dispatch.js +610 -0
- package/dist/server/app-page-element-builder.d.ts +96 -0
- package/dist/server/app-page-element-builder.js +205 -0
- package/dist/server/app-page-execution.d.ts +138 -0
- package/dist/server/app-page-execution.js +328 -0
- package/dist/server/app-page-head.d.ts +65 -0
- package/dist/server/app-page-head.js +228 -0
- package/dist/server/app-page-method.d.ts +15 -0
- package/dist/server/app-page-method.js +25 -0
- package/dist/server/app-page-params.d.ts +8 -0
- package/dist/server/app-page-params.js +39 -0
- package/dist/server/app-page-ppr-runtime.d.ts +7 -0
- package/dist/server/app-page-ppr-runtime.js +70 -0
- package/dist/server/app-page-probe.d.ts +134 -0
- package/dist/server/app-page-probe.js +276 -0
- package/dist/server/app-page-render-identity.d.ts +21 -0
- package/dist/server/app-page-render-identity.js +40 -0
- package/dist/server/app-page-render-observation.d.ts +36 -0
- package/dist/server/app-page-render-observation.js +82 -0
- package/dist/server/app-page-render.d.ts +111 -0
- package/dist/server/app-page-render.js +602 -0
- package/dist/server/app-page-request.d.ts +137 -0
- package/dist/server/app-page-request.js +216 -0
- package/dist/server/app-page-response.d.ts +68 -0
- package/dist/server/app-page-response.js +120 -0
- package/dist/server/app-page-route-wiring.d.ts +151 -0
- package/dist/server/app-page-route-wiring.js +452 -0
- package/dist/server/app-page-search-params-observation.d.ts +10 -0
- package/dist/server/app-page-search-params-observation.js +20 -0
- package/dist/server/app-page-segment-state.d.ts +9 -0
- package/dist/server/app-page-segment-state.js +80 -0
- package/dist/server/app-page-stream.d.ts +151 -0
- package/dist/server/app-page-stream.js +143 -0
- package/dist/server/app-pages-bridge.d.ts +63 -0
- package/dist/server/app-pages-bridge.js +63 -0
- package/dist/server/app-post-middleware-context.d.ts +15 -0
- package/dist/server/app-post-middleware-context.js +26 -0
- package/dist/server/app-ppr-fallback-shell-render.d.ts +18 -0
- package/dist/server/app-ppr-fallback-shell-render.js +26 -0
- package/dist/server/app-ppr-fallback-shell.d.ts +33 -0
- package/dist/server/app-ppr-fallback-shell.js +89 -0
- package/dist/server/app-prerender-endpoints.d.ts +18 -0
- package/dist/server/app-prerender-endpoints.js +94 -0
- package/dist/server/app-prerender-static-params.d.ts +30 -0
- package/dist/server/app-prerender-static-params.js +81 -0
- package/dist/server/app-render-dependency.d.ts +14 -0
- package/dist/server/app-render-dependency.js +41 -0
- package/dist/server/app-request-context.d.ts +20 -0
- package/dist/server/app-request-context.js +29 -0
- package/dist/server/app-route-handler-cache.d.ts +46 -0
- package/dist/server/app-route-handler-cache.js +78 -0
- package/dist/server/app-route-handler-dispatch.d.ts +49 -0
- package/dist/server/app-route-handler-dispatch.js +163 -0
- package/dist/server/app-route-handler-execution.d.ts +86 -0
- package/dist/server/app-route-handler-execution.js +128 -0
- package/dist/server/app-route-handler-policy.d.ts +55 -0
- package/dist/server/app-route-handler-policy.js +58 -0
- package/dist/server/app-route-handler-response.d.ts +28 -0
- package/dist/server/app-route-handler-response.js +145 -0
- package/dist/server/app-route-handler-runtime.d.ts +39 -0
- package/dist/server/app-route-handler-runtime.js +250 -0
- package/dist/server/app-route-module-loader.d.ts +91 -0
- package/dist/server/app-route-module-loader.js +83 -0
- package/dist/server/app-router-entry.d.ts +13 -0
- package/dist/server/app-router-entry.js +49 -0
- package/dist/server/app-rsc-cache-busting.d.ts +64 -0
- package/dist/server/app-rsc-cache-busting.js +206 -0
- package/dist/server/app-rsc-embedded-chunks.d.ts +8 -0
- package/dist/server/app-rsc-embedded-chunks.js +32 -0
- package/dist/server/app-rsc-error-handler.d.ts +20 -0
- package/dist/server/app-rsc-error-handler.js +28 -0
- package/dist/server/app-rsc-errors.d.ts +40 -0
- package/dist/server/app-rsc-errors.js +60 -0
- package/dist/server/app-rsc-handler.d.ts +201 -0
- package/dist/server/app-rsc-handler.js +538 -0
- package/dist/server/app-rsc-render-mode.d.ts +11 -0
- package/dist/server/app-rsc-render-mode.js +25 -0
- package/dist/server/app-rsc-request-normalization.d.ts +48 -0
- package/dist/server/app-rsc-request-normalization.js +75 -0
- package/dist/server/app-rsc-response-finalizer.d.ts +37 -0
- package/dist/server/app-rsc-response-finalizer.js +54 -0
- package/dist/server/app-rsc-route-matching.d.ts +93 -0
- package/dist/server/app-rsc-route-matching.js +134 -0
- package/dist/server/app-segment-config.d.ts +46 -0
- package/dist/server/app-segment-config.js +113 -0
- package/dist/server/app-server-action-execution.d.ts +219 -0
- package/dist/server/app-server-action-execution.js +767 -0
- package/dist/server/app-ssr-entry.d.ts +52 -0
- package/dist/server/app-ssr-entry.js +295 -0
- package/dist/server/app-ssr-error-meta.d.ts +13 -0
- package/dist/server/app-ssr-error-meta.js +48 -0
- package/dist/server/app-ssr-router-instance.d.ts +6 -0
- package/dist/server/app-ssr-router-instance.js +24 -0
- package/dist/server/app-ssr-stream.d.ts +60 -0
- package/dist/server/app-ssr-stream.js +408 -0
- package/dist/server/app-static-generation.d.ts +15 -0
- package/dist/server/app-static-generation.js +19 -0
- package/dist/server/app-visited-response-cache.d.ts +23 -0
- package/dist/server/app-visited-response-cache.js +19 -0
- package/dist/server/artifact-compatibility.d.ts +54 -0
- package/dist/server/artifact-compatibility.js +91 -0
- package/dist/server/before-interactive-head.d.ts +17 -0
- package/dist/server/before-interactive-head.js +35 -0
- package/dist/server/cache-control.d.ts +37 -0
- package/dist/server/cache-control.js +56 -0
- package/dist/server/cache-headers.d.ts +6 -0
- package/dist/server/cache-headers.js +17 -0
- package/dist/server/cache-proof.d.ts +364 -0
- package/dist/server/cache-proof.js +794 -0
- package/dist/server/client-reuse-manifest.d.ts +104 -0
- package/dist/server/client-reuse-manifest.js +209 -0
- package/dist/server/client-trace-metadata.d.ts +30 -0
- package/dist/server/client-trace-metadata.js +81 -0
- package/dist/server/cookie-utils.d.ts +12 -0
- package/dist/server/cookie-utils.js +18 -0
- package/dist/server/csp.d.ts +10 -0
- package/dist/server/csp.js +41 -0
- package/dist/server/default-global-error-module.d.ts +19 -0
- package/dist/server/default-global-error-module.js +18 -0
- package/dist/server/default-not-found-module.d.ts +19 -0
- package/dist/server/default-not-found-module.js +18 -0
- package/dist/server/defer-until-stream-consumed.d.ts +7 -0
- package/dist/server/defer-until-stream-consumed.js +34 -0
- package/dist/server/dev-error-overlay-store.d.ts +39 -0
- package/dist/server/dev-error-overlay-store.js +86 -0
- package/dist/server/dev-error-overlay.d.ts +51 -0
- package/dist/server/dev-error-overlay.js +1341 -0
- package/dist/server/dev-initial-server-error.d.ts +9 -0
- package/dist/server/dev-initial-server-error.js +26 -0
- package/dist/server/dev-lockfile.d.ts +109 -0
- package/dist/server/dev-lockfile.js +179 -0
- package/dist/server/dev-module-runner.d.ts +30 -0
- package/dist/server/dev-module-runner.js +91 -0
- package/dist/server/dev-origin-check.d.ts +62 -0
- package/dist/server/dev-origin-check.js +156 -0
- package/dist/server/dev-route-files.d.ts +6 -0
- package/dist/server/dev-route-files.js +71 -0
- package/dist/server/dev-server.d.ts +58 -0
- package/dist/server/dev-server.js +1114 -0
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/server/dev-stack-sourcemap-endpoint.js +4 -0
- package/dist/server/dev-stack-sourcemap.d.ts +43 -0
- package/dist/server/dev-stack-sourcemap.js +443 -0
- package/dist/server/document-initial-head.d.ts +6 -0
- package/dist/server/document-initial-head.js +33 -0
- package/dist/server/edge-api-runtime.d.ts +4 -0
- package/dist/server/edge-api-runtime.js +6 -0
- package/dist/server/file-based-metadata.d.ts +29 -0
- package/dist/server/file-based-metadata.js +401 -0
- package/dist/server/headers.d.ts +114 -0
- package/dist/server/headers.js +136 -0
- package/dist/server/html.d.ts +28 -0
- package/dist/server/html.js +41 -0
- package/dist/server/http-error-responses.d.ts +91 -0
- package/dist/server/http-error-responses.js +105 -0
- package/dist/server/hybrid-route-priority.d.ts +22 -0
- package/dist/server/hybrid-route-priority.js +33 -0
- package/dist/server/image-optimization.d.ts +130 -0
- package/dist/server/image-optimization.js +247 -0
- package/dist/server/implicit-tags.d.ts +6 -0
- package/dist/server/implicit-tags.js +44 -0
- package/dist/server/instrumentation-runtime.d.ts +49 -0
- package/dist/server/instrumentation-runtime.js +35 -0
- package/dist/server/instrumentation.d.ts +85 -0
- package/dist/server/instrumentation.js +130 -0
- package/dist/server/isr-cache.d.ts +127 -0
- package/dist/server/isr-cache.js +282 -0
- package/dist/server/isr-decision.d.ts +79 -0
- package/dist/server/isr-decision.js +70 -0
- package/dist/server/metadata-route-build-data.d.ts +24 -0
- package/dist/server/metadata-route-build-data.js +148 -0
- package/dist/server/metadata-route-response.d.ts +16 -0
- package/dist/server/metadata-route-response.js +205 -0
- package/dist/server/metadata-routes.d.ts +139 -0
- package/dist/server/metadata-routes.js +433 -0
- package/dist/server/middleware-matcher.d.ts +14 -0
- package/dist/server/middleware-matcher.js +111 -0
- package/dist/server/middleware-request-headers.d.ts +11 -0
- package/dist/server/middleware-request-headers.js +65 -0
- package/dist/server/middleware-response-headers.d.ts +12 -0
- package/dist/server/middleware-response-headers.js +42 -0
- package/dist/server/middleware-runtime.d.ts +67 -0
- package/dist/server/middleware-runtime.js +240 -0
- package/dist/server/middleware.d.ts +62 -0
- package/dist/server/middleware.js +114 -0
- package/dist/server/navigation-planner.d.ts +308 -0
- package/dist/server/navigation-planner.js +831 -0
- package/dist/server/navigation-trace.d.ts +68 -0
- package/dist/server/navigation-trace.js +71 -0
- package/dist/server/next-error-digest.d.ts +44 -0
- package/dist/server/next-error-digest.js +40 -0
- package/dist/server/normalize-path.d.ts +38 -0
- package/dist/server/normalize-path.js +70 -0
- package/dist/server/open-redirect.d.ts +12 -0
- package/dist/server/open-redirect.js +21 -0
- package/dist/server/operation-token.d.ts +40 -0
- package/dist/server/operation-token.js +85 -0
- package/dist/server/otel-tracer-extension.d.ts +45 -0
- package/dist/server/otel-tracer-extension.js +89 -0
- package/dist/server/pages-api-route.d.ts +83 -0
- package/dist/server/pages-api-route.js +75 -0
- package/dist/server/pages-asset-tags.d.ts +78 -0
- package/dist/server/pages-asset-tags.js +126 -0
- package/dist/server/pages-body-parser-config.d.ts +59 -0
- package/dist/server/pages-body-parser-config.js +77 -0
- package/dist/server/pages-data-route.d.ts +121 -0
- package/dist/server/pages-data-route.js +157 -0
- package/dist/server/pages-default-404.d.ts +30 -0
- package/dist/server/pages-default-404.js +38 -0
- package/dist/server/pages-dev-module-url.d.ts +4 -0
- package/dist/server/pages-dev-module-url.js +15 -0
- package/dist/server/pages-document-initial-props.d.ts +77 -0
- package/dist/server/pages-document-initial-props.js +109 -0
- package/dist/server/pages-get-initial-props.d.ts +67 -0
- package/dist/server/pages-get-initial-props.js +92 -0
- package/dist/server/pages-i18n.d.ts +106 -0
- package/dist/server/pages-i18n.js +183 -0
- package/dist/server/pages-media-type.d.ts +15 -0
- package/dist/server/pages-media-type.js +24 -0
- package/dist/server/pages-node-compat.d.ts +55 -0
- package/dist/server/pages-node-compat.js +235 -0
- package/dist/server/pages-page-data.d.ts +223 -0
- package/dist/server/pages-page-data.js +484 -0
- package/dist/server/pages-page-handler.d.ts +100 -0
- package/dist/server/pages-page-handler.js +403 -0
- package/dist/server/pages-page-method.d.ts +47 -0
- package/dist/server/pages-page-method.js +17 -0
- package/dist/server/pages-page-response.d.ts +138 -0
- package/dist/server/pages-page-response.js +285 -0
- package/dist/server/pages-readiness.d.ts +36 -0
- package/dist/server/pages-readiness.js +21 -0
- package/dist/server/pages-request-pipeline.d.ts +116 -0
- package/dist/server/pages-request-pipeline.js +311 -0
- package/dist/server/pages-revalidate.d.ts +15 -0
- package/dist/server/pages-revalidate.js +19 -0
- package/dist/server/pages-serializable-props.d.ts +24 -0
- package/dist/server/pages-serializable-props.js +67 -0
- package/dist/server/pregenerated-concrete-paths.d.ts +16 -0
- package/dist/server/pregenerated-concrete-paths.js +61 -0
- package/dist/server/prerender-manifest.d.ts +33 -0
- package/dist/server/prerender-manifest.js +54 -0
- package/dist/server/prerender-route-params.d.ts +23 -0
- package/dist/server/prerender-route-params.js +113 -0
- package/dist/server/prerender-work-unit-setup.d.ts +6 -0
- package/dist/server/prerender-work-unit-setup.js +28 -0
- package/dist/server/prod-server.d.ts +148 -0
- package/dist/server/prod-server.js +1136 -0
- package/dist/server/proxy-trust.d.ts +40 -0
- package/dist/server/proxy-trust.js +68 -0
- package/dist/server/request-log.d.ts +39 -0
- package/dist/server/request-log.js +56 -0
- package/dist/server/request-pipeline.d.ts +187 -0
- package/dist/server/request-pipeline.js +447 -0
- package/dist/server/rsc-stream-hints.d.ts +10 -0
- package/dist/server/rsc-stream-hints.js +41 -0
- package/dist/server/seed-cache.d.ts +29 -0
- package/dist/server/seed-cache.js +125 -0
- package/dist/server/server-action-not-found.d.ts +21 -0
- package/dist/server/server-action-not-found.js +62 -0
- package/dist/server/server-globals.d.ts +4 -0
- package/dist/server/server-globals.js +35 -0
- package/dist/server/skip-cache-proof.d.ts +61 -0
- package/dist/server/skip-cache-proof.js +168 -0
- package/dist/server/socket-error-backstop.d.ts +34 -0
- package/dist/server/socket-error-backstop.js +200 -0
- package/dist/server/static-file-cache.d.ts +56 -0
- package/dist/server/static-file-cache.js +231 -0
- package/dist/server/static-layout-client-reuse-proof.d.ts +15 -0
- package/dist/server/static-layout-client-reuse-proof.js +33 -0
- package/dist/server/streaming-metadata.d.ts +4 -0
- package/dist/server/streaming-metadata.js +8 -0
- package/dist/server/worker-utils.d.ts +7 -0
- package/dist/server/worker-utils.js +99 -0
- package/dist/shims/amp.d.ts +19 -0
- package/dist/shims/amp.js +23 -0
- package/dist/shims/app-router-scroll-state.d.ts +15 -0
- package/dist/shims/app-router-scroll-state.js +61 -0
- package/dist/shims/app-router-scroll.d.ts +29 -0
- package/dist/shims/app-router-scroll.js +141 -0
- package/dist/shims/app.d.ts +42 -0
- package/dist/shims/app.js +48 -0
- package/dist/shims/before-interactive-context.d.ts +40 -0
- package/dist/shims/before-interactive-context.js +8 -0
- package/dist/shims/cache-for-request.d.ts +57 -0
- package/dist/shims/cache-for-request.js +72 -0
- package/dist/shims/cache-handler.d.ts +106 -0
- package/dist/shims/cache-handler.js +176 -0
- package/dist/shims/cache-request-state.d.ts +47 -0
- package/dist/shims/cache-request-state.js +126 -0
- package/dist/shims/cache-runtime.d.ts +83 -0
- package/dist/shims/cache-runtime.js +452 -0
- package/dist/shims/cache.d.ts +145 -0
- package/dist/shims/cache.js +401 -0
- package/dist/shims/cdn-cache.d.ts +125 -0
- package/dist/shims/cdn-cache.js +100 -0
- package/dist/shims/client-hook-error.d.ts +13 -0
- package/dist/shims/client-hook-error.js +17 -0
- package/dist/shims/client-locale.d.ts +14 -0
- package/dist/shims/client-locale.js +11 -0
- package/dist/shims/client-only.d.ts +1 -0
- package/dist/shims/client-only.js +1 -0
- package/dist/shims/compat-router.d.ts +16 -0
- package/dist/shims/compat-router.js +25 -0
- package/dist/shims/config.d.ts +28 -0
- package/dist/shims/config.js +21 -0
- package/dist/shims/constants.d.ts +130 -0
- package/dist/shims/constants.js +167 -0
- package/dist/shims/default-global-error.d.ts +31 -0
- package/dist/shims/default-global-error.js +179 -0
- package/dist/shims/default-not-found.d.ts +11 -0
- package/dist/shims/default-not-found.js +59 -0
- package/dist/shims/document.d.ts +92 -0
- package/dist/shims/document.js +76 -0
- package/dist/shims/dynamic-preload-chunks.d.ts +8 -0
- package/dist/shims/dynamic-preload-chunks.js +79 -0
- package/dist/shims/dynamic.d.ts +35 -0
- package/dist/shims/dynamic.js +204 -0
- package/dist/shims/error-boundary-navigation.d.ts +7 -0
- package/dist/shims/error-boundary-navigation.js +44 -0
- package/dist/shims/error-boundary.d.ts +155 -0
- package/dist/shims/error-boundary.js +342 -0
- package/dist/shims/error.d.ts +31 -0
- package/dist/shims/error.js +123 -0
- package/dist/shims/error.react-server.d.ts +9 -0
- package/dist/shims/error.react-server.js +6 -0
- package/dist/shims/fetch-cache.d.ts +136 -0
- package/dist/shims/fetch-cache.js +766 -0
- package/dist/shims/font-google-base.d.ts +83 -0
- package/dist/shims/font-google-base.js +290 -0
- package/dist/shims/font-google.d.ts +2 -0
- package/dist/shims/font-google.js +2 -0
- package/dist/shims/font-local.d.ts +50 -0
- package/dist/shims/font-local.js +195 -0
- package/dist/shims/font-utils.d.ts +56 -0
- package/dist/shims/font-utils.js +107 -0
- package/dist/shims/form.d.ts +19 -0
- package/dist/shims/form.js +236 -0
- package/dist/shims/hash-scroll.d.ts +10 -0
- package/dist/shims/hash-scroll.js +47 -0
- package/dist/shims/head-state.d.ts +16 -0
- package/dist/shims/head-state.js +43 -0
- package/dist/shims/head.d.ts +73 -0
- package/dist/shims/head.js +340 -0
- package/dist/shims/headers.d.ts +253 -0
- package/dist/shims/headers.js +754 -0
- package/dist/shims/i18n-context.d.ts +22 -0
- package/dist/shims/i18n-context.js +42 -0
- package/dist/shims/i18n-state.d.ts +14 -0
- package/dist/shims/i18n-state.js +38 -0
- package/dist/shims/image-config.d.ts +45 -0
- package/dist/shims/image-config.js +85 -0
- package/dist/shims/image.d.ts +55 -0
- package/dist/shims/image.js +582 -0
- package/dist/shims/internal/als-registry.d.ts +14 -0
- package/dist/shims/internal/als-registry.js +80 -0
- package/dist/shims/internal/api-utils.d.ts +14 -0
- package/dist/shims/internal/api-utils.js +1 -0
- package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
- package/dist/shims/internal/app-page-props-cache-key.js +16 -0
- package/dist/shims/internal/app-route-detection.d.ts +39 -0
- package/dist/shims/internal/app-route-detection.js +62 -0
- package/dist/shims/internal/app-router-context.d.ts +31 -0
- package/dist/shims/internal/app-router-context.js +28 -0
- package/dist/shims/internal/cookie-serialize.d.ts +45 -0
- package/dist/shims/internal/cookie-serialize.js +49 -0
- package/dist/shims/internal/cookies.d.ts +2 -0
- package/dist/shims/internal/cookies.js +2 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +31 -0
- package/dist/shims/internal/hybrid-client-route-owner.js +143 -0
- package/dist/shims/internal/interpolate-as.d.ts +25 -0
- package/dist/shims/internal/interpolate-as.js +196 -0
- package/dist/shims/internal/link-status-registry.d.ts +43 -0
- package/dist/shims/internal/link-status-registry.js +42 -0
- package/dist/shims/internal/make-hanging-promise.d.ts +15 -0
- package/dist/shims/internal/make-hanging-promise.js +44 -0
- package/dist/shims/internal/navigation-untracked.d.ts +35 -0
- package/dist/shims/internal/navigation-untracked.js +56 -0
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +54 -0
- package/dist/shims/internal/pages-data-fetch-dedup.js +121 -0
- package/dist/shims/internal/pages-data-target.d.ts +62 -0
- package/dist/shims/internal/pages-data-target.js +98 -0
- package/dist/shims/internal/pages-data-url.d.ts +41 -0
- package/dist/shims/internal/pages-data-url.js +71 -0
- package/dist/shims/internal/pages-router-accessor.d.ts +19 -0
- package/dist/shims/internal/pages-router-accessor.js +13 -0
- package/dist/shims/internal/route-pattern-for-warning.d.ts +27 -0
- package/dist/shims/internal/route-pattern-for-warning.js +40 -0
- package/dist/shims/internal/router-context.d.ts +7 -0
- package/dist/shims/internal/router-context.js +13 -0
- package/dist/shims/internal/utils.d.ts +52 -0
- package/dist/shims/internal/utils.js +27 -0
- package/dist/shims/internal/work-unit-async-storage.d.ts +30 -0
- package/dist/shims/internal/work-unit-async-storage.js +17 -0
- package/dist/shims/layout-segment-context.d.ts +24 -0
- package/dist/shims/layout-segment-context.js +39 -0
- package/dist/shims/legacy-image.d.ts +41 -0
- package/dist/shims/legacy-image.js +49 -0
- package/dist/shims/link-prefetch.d.ts +41 -0
- package/dist/shims/link-prefetch.js +43 -0
- package/dist/shims/link.d.ts +102 -0
- package/dist/shims/link.js +687 -0
- package/dist/shims/metadata.d.ts +285 -0
- package/dist/shims/metadata.js +820 -0
- package/dist/shims/navigation-context-state.d.ts +40 -0
- package/dist/shims/navigation-context-state.js +116 -0
- package/dist/shims/navigation-errors.d.ts +55 -0
- package/dist/shims/navigation-errors.js +110 -0
- package/dist/shims/navigation-server.d.ts +3 -0
- package/dist/shims/navigation-server.js +3 -0
- package/dist/shims/navigation-state.d.ts +25 -0
- package/dist/shims/navigation-state.js +66 -0
- package/dist/shims/navigation.d.ts +286 -0
- package/dist/shims/navigation.js +1206 -0
- package/dist/shims/navigation.react-server.d.ts +14 -0
- package/dist/shims/navigation.react-server.js +32 -0
- package/dist/shims/offline.d.ts +4 -0
- package/dist/shims/offline.js +15 -0
- package/dist/shims/og.d.ts +17 -0
- package/dist/shims/og.js +48 -0
- package/dist/shims/pages-router-runtime.d.ts +12 -0
- package/dist/shims/pages-router-runtime.js +24 -0
- package/dist/shims/ppr-fallback-shell.d.ts +33 -0
- package/dist/shims/ppr-fallback-shell.js +170 -0
- package/dist/shims/readonly-url-search-params.d.ts +13 -0
- package/dist/shims/readonly-url-search-params.js +26 -0
- package/dist/shims/request-context.d.ts +58 -0
- package/dist/shims/request-context.js +45 -0
- package/dist/shims/request-state-types.d.ts +12 -0
- package/dist/shims/request-state-types.js +1 -0
- package/dist/shims/root-params.d.ts +12 -0
- package/dist/shims/root-params.js +30 -0
- package/dist/shims/router-state.d.ts +32 -0
- package/dist/shims/router-state.js +39 -0
- package/dist/shims/router.d.ts +192 -0
- package/dist/shims/router.js +1786 -0
- package/dist/shims/script-nonce-context.d.ts +11 -0
- package/dist/shims/script-nonce-context.js +23 -0
- package/dist/shims/script.d.ts +43 -0
- package/dist/shims/script.js +370 -0
- package/dist/shims/server-only.d.ts +1 -0
- package/dist/shims/server-only.js +1 -0
- package/dist/shims/server.d.ts +323 -0
- package/dist/shims/server.js +729 -0
- package/dist/shims/slot.d.ts +45 -0
- package/dist/shims/slot.js +230 -0
- package/dist/shims/thenable-params.d.ts +11 -0
- package/dist/shims/thenable-params.js +176 -0
- package/dist/shims/unified-request-context.d.ts +68 -0
- package/dist/shims/unified-request-context.js +86 -0
- package/dist/shims/unrecognized-action-error.d.ts +34 -0
- package/dist/shims/unrecognized-action-error.js +39 -0
- package/dist/shims/url-safety.d.ts +34 -0
- package/dist/shims/url-safety.js +70 -0
- package/dist/shims/url-utils.d.ts +51 -0
- package/dist/shims/url-utils.js +156 -0
- package/dist/shims/use-merged-ref.d.ts +6 -0
- package/dist/shims/use-merged-ref.js +38 -0
- package/dist/shims/web-vitals.d.ts +8 -0
- package/dist/shims/web-vitals.js +22 -0
- package/dist/typegen.d.ts +9 -0
- package/dist/typegen.js +228 -0
- package/dist/utils/asset-prefix.d.ts +96 -0
- package/dist/utils/asset-prefix.js +122 -0
- package/dist/utils/base-path.d.ts +31 -0
- package/dist/utils/base-path.js +45 -0
- package/dist/utils/built-asset-url.d.ts +4 -0
- package/dist/utils/built-asset-url.js +11 -0
- package/dist/utils/cache-control-metadata.d.ts +4 -0
- package/dist/utils/cache-control-metadata.js +12 -0
- package/dist/utils/client-build-manifest.d.ts +21 -0
- package/dist/utils/client-build-manifest.js +87 -0
- package/dist/utils/client-entry-manifest.d.ts +11 -0
- package/dist/utils/client-entry-manifest.js +29 -0
- package/dist/utils/client-runtime-metadata.d.ts +45 -0
- package/dist/utils/client-runtime-metadata.js +63 -0
- package/dist/utils/commonjs-loader.d.ts +16 -0
- package/dist/utils/commonjs-loader.js +100 -0
- package/dist/utils/compare.d.ts +4 -0
- package/dist/utils/compare.js +8 -0
- package/dist/utils/deployment-id.d.ts +8 -0
- package/dist/utils/deployment-id.js +22 -0
- package/dist/utils/dev-error-recovery-event.d.ts +4 -0
- package/dist/utils/dev-error-recovery-event.js +4 -0
- package/dist/utils/domain-locale.d.ts +26 -0
- package/dist/utils/domain-locale.js +50 -0
- package/dist/utils/encode-cache-tag.d.ts +30 -0
- package/dist/utils/encode-cache-tag.js +36 -0
- package/dist/utils/error-cause.d.ts +4 -0
- package/dist/utils/error-cause.js +95 -0
- package/dist/utils/has-trailing-comma.d.ts +24 -0
- package/dist/utils/has-trailing-comma.js +62 -0
- package/dist/utils/hash.d.ts +24 -0
- package/dist/utils/hash.js +55 -0
- package/dist/utils/html-limited-bots.d.ts +21 -0
- package/dist/utils/html-limited-bots.js +35 -0
- package/dist/utils/lazy-chunks.d.ts +59 -0
- package/dist/utils/lazy-chunks.js +112 -0
- package/dist/utils/manifest-paths.d.ts +30 -0
- package/dist/utils/manifest-paths.js +66 -0
- package/dist/utils/mdx-scan.d.ts +9 -0
- package/dist/utils/mdx-scan.js +34 -0
- package/dist/utils/navigation-signal.d.ts +4 -0
- package/dist/utils/navigation-signal.js +12 -0
- package/dist/utils/number.d.ts +4 -0
- package/dist/utils/number.js +6 -0
- package/dist/utils/parse-cookie.d.ts +13 -0
- package/dist/utils/parse-cookie.js +52 -0
- package/dist/utils/path.d.ts +22 -0
- package/dist/utils/path.js +30 -0
- package/dist/utils/prerender-output-paths.d.ts +14 -0
- package/dist/utils/prerender-output-paths.js +22 -0
- package/dist/utils/project.d.ts +76 -0
- package/dist/utils/project.js +213 -0
- package/dist/utils/promise.d.ts +4 -0
- package/dist/utils/promise.js +6 -0
- package/dist/utils/public-routes.d.ts +4 -0
- package/dist/utils/public-routes.js +48 -0
- package/dist/utils/query.d.ts +49 -0
- package/dist/utils/query.js +122 -0
- package/dist/utils/record.d.ts +4 -0
- package/dist/utils/record.js +6 -0
- package/dist/utils/regex.d.ts +4 -0
- package/dist/utils/regex.js +6 -0
- package/dist/utils/safe-json-file.d.ts +17 -0
- package/dist/utils/safe-json-file.js +23 -0
- package/dist/utils/sorted-array.d.ts +8 -0
- package/dist/utils/sorted-array.js +20 -0
- package/dist/utils/text-stream.d.ts +28 -0
- package/dist/utils/text-stream.js +64 -0
- package/dist/utils/vinext-root.d.ts +23 -0
- package/dist/utils/vinext-root.js +29 -0
- package/dist/utils/virtual-module.d.ts +5 -0
- package/dist/utils/virtual-module.js +0 -0
- package/dist/utils/vite-version.d.ts +21 -0
- package/dist/utils/vite-version.js +42 -0
- package/package.json +145 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
//#region src/routing/utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Route precedence — lower score is higher priority.
|
|
4
|
+
* Matches Next.js specificity rules:
|
|
5
|
+
* 1. Static routes first (scored by segment count, more = more specific)
|
|
6
|
+
* 2. Dynamic segments penalized by position
|
|
7
|
+
* 3. Catch-all comes after dynamic
|
|
8
|
+
* 4. Optional catch-all last
|
|
9
|
+
* 5. Lexicographic tiebreaker for determinism
|
|
10
|
+
*
|
|
11
|
+
* Key insight: routes with a static prefix before a dynamic/catch-all segment
|
|
12
|
+
* should have higher priority than bare dynamic/catch-all routes at the same
|
|
13
|
+
* depth. E.g., /_sites/:subdomain should match before /:subdomain, and
|
|
14
|
+
* /_sites/:subdomain/:slug* should match before /:slug*.
|
|
15
|
+
*
|
|
16
|
+
* The static-prefix reduction uses a small value (-50 per segment) so that:
|
|
17
|
+
* - It beats the per-dynamic-segment penalty (100), placing prefix routes
|
|
18
|
+
* above their no-prefix equivalents.
|
|
19
|
+
* - It is small enough that infix-static bonuses (-500) and catch-all
|
|
20
|
+
* penalties (1000+) are not swamped, preserving their relative ordering.
|
|
21
|
+
* E.g. /:locale/blog/:path+ (with infix "blog") correctly beats /:locale/:path+
|
|
22
|
+
* even when both share the same "locale-test" static prefix.
|
|
23
|
+
* - Note: dynamic routes CAN score negative (e.g. /a/:b/c/:d = -346), but
|
|
24
|
+
* this is harmless because the trie matcher (route-trie.ts) checks static
|
|
25
|
+
* children before dynamic children at each node, so purely-static routes
|
|
26
|
+
* still win at request time regardless of sort-order score.
|
|
27
|
+
*/
|
|
28
|
+
function routePrecedence(pattern) {
|
|
29
|
+
const parts = pattern.split("/").filter(Boolean);
|
|
30
|
+
let score = 0;
|
|
31
|
+
let staticPrefixCount = 0;
|
|
32
|
+
for (const p of parts) {
|
|
33
|
+
if (p.startsWith(":") || p.endsWith("+") || p.endsWith("*")) break;
|
|
34
|
+
staticPrefixCount++;
|
|
35
|
+
}
|
|
36
|
+
for (let i = 0; i < parts.length; i++) {
|
|
37
|
+
const p = parts[i];
|
|
38
|
+
if (p.endsWith("+")) score += 1e3 + i;
|
|
39
|
+
else if (p.endsWith("*")) score += 2e3 + i;
|
|
40
|
+
else if (p.startsWith(":")) score += 100 + i;
|
|
41
|
+
else if (i >= staticPrefixCount) score -= 500;
|
|
42
|
+
}
|
|
43
|
+
if (parts.some((p) => p.startsWith(":") || p.endsWith("+") || p.endsWith("*")) && staticPrefixCount > 0) score -= staticPrefixCount * 50;
|
|
44
|
+
return score;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sort routes by precedence — lower score sorts first (higher priority), with a
|
|
48
|
+
* lexicographic tiebreaker on the pattern for determinism. Sorts in place and
|
|
49
|
+
* returns the same array (mirrors `Array.prototype.sort`).
|
|
50
|
+
*
|
|
51
|
+
* `routePrecedence` is a pure function of the pattern, so each pattern's score
|
|
52
|
+
* is computed exactly once up front (decorate-sort) instead of ~2·log n times
|
|
53
|
+
* by a comparator that re-parses on every comparison. The `localeCompare`
|
|
54
|
+
* tiebreaker already guarantees a total order, so the result is byte-identical
|
|
55
|
+
* to comparing precedence inline.
|
|
56
|
+
*
|
|
57
|
+
* Usage: sortRoutes(routes)
|
|
58
|
+
*/
|
|
59
|
+
function sortRoutes(routes) {
|
|
60
|
+
const scores = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const route of routes) if (!scores.has(route.pattern)) scores.set(route.pattern, routePrecedence(route.pattern));
|
|
62
|
+
return routes.sort((a, b) => {
|
|
63
|
+
const diff = (scores.get(a.pattern) ?? 0) - (scores.get(b.pattern) ?? 0);
|
|
64
|
+
return diff !== 0 ? diff : a.pattern.localeCompare(b.pattern);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Single source of truth for hybrid App/Pages route ownership.
|
|
69
|
+
*
|
|
70
|
+
* Mirrors Next.js's DefaultRouteMatcherManager ordering: Pages providers
|
|
71
|
+
* are registered before App providers, then merged dynamic matchers sort
|
|
72
|
+
* together. Returns the router that should own a request/navigation to
|
|
73
|
+
* a URL that matched BOTH routers.
|
|
74
|
+
*
|
|
75
|
+
* Centralised so the server's request handling and the client's link /
|
|
76
|
+
* prefetch / programmatic-navigation paths all reach the same owner for
|
|
77
|
+
* the same (pages pattern, app pattern) pair. This intentionally implements
|
|
78
|
+
* Next.js's segment-tree ordering directly instead of vinext's broader
|
|
79
|
+
* `sortRoutes()` score heuristic. It only arbitrates two routes that already
|
|
80
|
+
* matched the same URL; each router's own trie ordering remains unchanged.
|
|
81
|
+
*
|
|
82
|
+
* Usage:
|
|
83
|
+
* compareHybridRoutePatterns("/:slug", true, "/:slug", true) // → "pages"
|
|
84
|
+
* compareHybridRoutePatterns("/_sites/:slug*", true, "/:slug*", true) // → "pages"
|
|
85
|
+
* compareHybridRoutePatterns("/:path+", true, "/dashboard", false) // → "app"
|
|
86
|
+
* compareHybridRoutePatterns("/", false, "/", false) // → "app"
|
|
87
|
+
*/
|
|
88
|
+
function compareHybridRoutePatterns(pagesPattern, pagesIsDynamic, appPattern, appIsDynamic) {
|
|
89
|
+
if (pagesPattern === appPattern) throw new Error(`Conflicting app and page routes found for "${pagesPattern}"`);
|
|
90
|
+
if (!pagesIsDynamic) return appIsDynamic ? "pages" : "app";
|
|
91
|
+
if (!appIsDynamic) return "app";
|
|
92
|
+
const pagesSegments = pagesPattern.split("/").filter(Boolean);
|
|
93
|
+
const appSegments = appPattern.split("/").filter(Boolean);
|
|
94
|
+
const segmentRank = (segment) => {
|
|
95
|
+
if (!segment.startsWith(":")) return 0;
|
|
96
|
+
if (segment.endsWith("*")) return 3;
|
|
97
|
+
if (segment.endsWith("+")) return 2;
|
|
98
|
+
return 1;
|
|
99
|
+
};
|
|
100
|
+
for (let index = 0; index < Math.min(pagesSegments.length, appSegments.length); index++) {
|
|
101
|
+
const pagesRank = segmentRank(pagesSegments[index]);
|
|
102
|
+
const appRank = segmentRank(appSegments[index]);
|
|
103
|
+
if (pagesRank !== appRank) return pagesRank < appRank ? "pages" : "app";
|
|
104
|
+
}
|
|
105
|
+
if (pagesSegments.length !== appSegments.length) return pagesSegments.length < appSegments.length ? "pages" : "app";
|
|
106
|
+
return "pages";
|
|
107
|
+
}
|
|
108
|
+
const PATH_DELIMITER_REGEX = /([/#?\\]|%(2f|23|3f|5c))/gi;
|
|
109
|
+
function encodePathDelimiters(segment) {
|
|
110
|
+
return segment.replace(PATH_DELIMITER_REGEX, (char) => encodeURIComponent(char));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Decode a filesystem or URL path segment while preserving encoded path delimiters.
|
|
114
|
+
* Mirrors Next.js segment-wise decoding so "%5F" becomes "_" but "%2F" stays "%2F".
|
|
115
|
+
*/
|
|
116
|
+
function decodeRouteSegment(segment) {
|
|
117
|
+
try {
|
|
118
|
+
return encodePathDelimiters(decodeURIComponent(segment));
|
|
119
|
+
} catch {
|
|
120
|
+
return segment;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Strict variant for request pipelines that should reject malformed percent-encoding.
|
|
125
|
+
*/
|
|
126
|
+
function decodeRouteSegmentStrict(segment) {
|
|
127
|
+
return encodePathDelimiters(decodeURIComponent(segment));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Normalize a pathname for route matching by decoding each segment independently.
|
|
131
|
+
* This prevents encoded slashes from turning into real path separators.
|
|
132
|
+
*/
|
|
133
|
+
function normalizePathnameForRouteMatch(pathname) {
|
|
134
|
+
return pathname.split("/").map((segment) => decodeRouteSegment(segment)).join("/");
|
|
135
|
+
}
|
|
136
|
+
function splitPathnameForRouteMatch(pathname) {
|
|
137
|
+
return normalizePathnameForRouteMatch(pathname).split("/").filter(Boolean);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Strict pathname normalization for live request handling.
|
|
141
|
+
* Throws on malformed percent-encoding so callers can return 400.
|
|
142
|
+
*/
|
|
143
|
+
function normalizePathnameForRouteMatchStrict(pathname) {
|
|
144
|
+
return pathname.split("/").map((segment) => decodeRouteSegmentStrict(segment)).join("/");
|
|
145
|
+
}
|
|
146
|
+
function decodeMatchedParam(value) {
|
|
147
|
+
try {
|
|
148
|
+
return decodeURIComponent(value);
|
|
149
|
+
} catch {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Build a params object from ordered entries, preserving insertion order.
|
|
155
|
+
*
|
|
156
|
+
* Used by trie matchers to reconstruct the params Record after collecting
|
|
157
|
+
* entries in declaration order via DFS backtracking. Object.create(null)
|
|
158
|
+
* avoids prototype pollution.
|
|
159
|
+
*
|
|
160
|
+
* @param entries - Ordered [paramName, value] tuples from forward traversal
|
|
161
|
+
*/
|
|
162
|
+
function buildParams(entries) {
|
|
163
|
+
const params = Object.create(null);
|
|
164
|
+
for (const [key, value] of entries) params[key] = value;
|
|
165
|
+
return params;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Decode captured route params with `decodeURIComponent`, mirroring Next.js
|
|
169
|
+
* route-matcher.ts:25-27. Mutates the params object in place. Catch-all
|
|
170
|
+
* arrays are decoded element-wise. Malformed escapes are preserved (the
|
|
171
|
+
* strict normalization layer rejects them at the request boundary).
|
|
172
|
+
*/
|
|
173
|
+
function decodeMatchedParams(params) {
|
|
174
|
+
for (const key of Object.keys(params)) {
|
|
175
|
+
const value = params[key];
|
|
176
|
+
if (Array.isArray(value)) params[key] = value.map(decodeMatchedParam);
|
|
177
|
+
else params[key] = decodeMatchedParam(value);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Check whether a path segment is invisible in the URL (route groups, parallel
|
|
182
|
+
* slots, "."). Single source of truth shared by the route graph (Node) and
|
|
183
|
+
* browser-side bfcache identity logic. Lives in this browser-safe utils module
|
|
184
|
+
* so importing it does not drag node:path/node:fs into the client bundle.
|
|
185
|
+
*/
|
|
186
|
+
function isInvisibleSegment(segment) {
|
|
187
|
+
if (segment === ".") return true;
|
|
188
|
+
if (segment.startsWith("(") && segment.endsWith(")")) return true;
|
|
189
|
+
if (segment.startsWith("@")) return true;
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
/** Split a pathname into its non-empty segments without decoding. */
|
|
193
|
+
function splitPathSegments(pathname) {
|
|
194
|
+
return pathname.split("/").filter(Boolean);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Catch-all filesystem segment, e.g. `[...slug]`. Browser-safe predicate shared
|
|
198
|
+
* with the route graph's segment parsing (dynamicParamNameFromSegment) so the
|
|
199
|
+
* bracket conventions live in one place. The length guard rejects empty names
|
|
200
|
+
* (`[...]`).
|
|
201
|
+
*/
|
|
202
|
+
function isCatchAllSegment(segment) {
|
|
203
|
+
return segment.startsWith("[...") && segment.endsWith("]") && segment.length > 5;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Optional-catch-all filesystem segment, e.g. `[[...slug]]`. Unlike a catch-all,
|
|
207
|
+
* this matches zero or more URL segments.
|
|
208
|
+
*/
|
|
209
|
+
function isOptionalCatchAllSegment(segment) {
|
|
210
|
+
return segment.startsWith("[[...") && segment.endsWith("]]") && segment.length > 7;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Count how many pathname segments a tree path's *visible* segments consume,
|
|
214
|
+
* given the total number of pathname segments available.
|
|
215
|
+
*
|
|
216
|
+
* This is the minimal pure slice of the canonical filesystem-segment →
|
|
217
|
+
* URL-segment mapping in `app-route-graph.ts` (`convertSegmentsToRouteParts`),
|
|
218
|
+
* extracted here so browser-side bfcache identity logic can share it without
|
|
219
|
+
* importing the Node-bound route graph module. `convertSegmentsToRouteParts`
|
|
220
|
+
* remains the source of truth for how each segment kind maps to a URL part.
|
|
221
|
+
*
|
|
222
|
+
* Each ordinary visible segment (static or `[x]`) consumes exactly one pathname
|
|
223
|
+
* segment. A catch-all (`[...x]`) is terminal and consumes every remaining
|
|
224
|
+
* pathname segment. An optional-catch-all (`[[...x]]`) is also terminal but may
|
|
225
|
+
* match zero segments, so it consumes only the remaining pathname segments
|
|
226
|
+
* (which is zero once preceding segments have already consumed the pathname) —
|
|
227
|
+
* never more than are actually present.
|
|
228
|
+
*
|
|
229
|
+
* @param visibleTreePathSegments URL-visible tree-path segments (callers must
|
|
230
|
+
* pre-filter invisible segments via `isInvisibleSegment`).
|
|
231
|
+
* @param pathnameSegmentCount Total number of pathname segments available.
|
|
232
|
+
*/
|
|
233
|
+
function countConsumedPathnameSegments(visibleTreePathSegments, pathnameSegmentCount) {
|
|
234
|
+
let consumed = 0;
|
|
235
|
+
for (const segment of visibleTreePathSegments) {
|
|
236
|
+
if (isCatchAllSegment(segment) || isOptionalCatchAllSegment(segment)) return Math.max(consumed, pathnameSegmentCount);
|
|
237
|
+
consumed += 1;
|
|
238
|
+
}
|
|
239
|
+
return consumed;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
export { buildParams, compareHybridRoutePatterns, countConsumedPathnameSegments, decodeMatchedParams, decodeRouteSegment, isCatchAllSegment, isInvisibleSegment, isOptionalCatchAllSegment, normalizePathnameForRouteMatch, normalizePathnameForRouteMatchStrict, sortRoutes, splitPathSegments, splitPathnameForRouteMatch };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IncomingMessage } from "node:http";
|
|
2
|
+
|
|
3
|
+
//#region src/server/accept-encoding.d.ts
|
|
4
|
+
type ContentEncoding = "zstd" | "br" | "gzip" | "deflate";
|
|
5
|
+
type NegotiatedEncoding = ContentEncoding | "identity";
|
|
6
|
+
/** Parsed explicit coding qualities plus the wildcard quality, when present. */
|
|
7
|
+
type ParsedAcceptEncoding = {
|
|
8
|
+
qualities: Map<string, number>;
|
|
9
|
+
orders: Map<string, number>;
|
|
10
|
+
wildcardQuality: number | null;
|
|
11
|
+
};
|
|
12
|
+
/** Parse an Accept-Encoding header into exact-token numeric qualities. */
|
|
13
|
+
declare function parseAcceptedEncodings(accept: string): ParsedAcceptEncoding;
|
|
14
|
+
/** Return the effective quality for a coding, including wildcard/identity rules. */
|
|
15
|
+
declare function getEncodingQuality(parsed: ParsedAcceptEncoding, encoding: string): number;
|
|
16
|
+
declare function isEncodingAccepted(parsed: ParsedAcceptEncoding, encoding: string): boolean;
|
|
17
|
+
/** Choose the highest-quality available coding, using array order as the tie-breaker. */
|
|
18
|
+
declare function selectAcceptedEncoding<T extends string>(parsed: ParsedAcceptEncoding, available: readonly T[]): T | null;
|
|
19
|
+
/**
|
|
20
|
+
* Select a content coding while matching Next.js's compression middleware:
|
|
21
|
+
* an explicit identity preference can win, but implicit identity remains a
|
|
22
|
+
* fallback rather than suppressing an otherwise acceptable encoding.
|
|
23
|
+
*/
|
|
24
|
+
declare function selectContentEncoding<T extends ContentEncoding>(parsed: ParsedAcceptEncoding, available: readonly T[]): T | "identity";
|
|
25
|
+
declare const HAS_ZSTD: boolean;
|
|
26
|
+
/** Select by client q-value first, then zstd > br > gzip > deflate > identity. */
|
|
27
|
+
declare function negotiateEncoding(req: IncomingMessage): NegotiatedEncoding;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { HAS_ZSTD, NegotiatedEncoding, ParsedAcceptEncoding, getEncodingQuality, isEncodingAccepted, negotiateEncoding, parseAcceptedEncodings, selectAcceptedEncoding, selectContentEncoding };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import zlib from "node:zlib";
|
|
2
|
+
//#region src/server/accept-encoding.ts
|
|
3
|
+
/** Parse an Accept-Encoding header into exact-token numeric qualities. */
|
|
4
|
+
function parseAcceptedEncodings(accept) {
|
|
5
|
+
const qualities = /* @__PURE__ */ new Map();
|
|
6
|
+
const orders = /* @__PURE__ */ new Map();
|
|
7
|
+
let wildcardQuality = null;
|
|
8
|
+
for (const [order, part] of accept.split(",").entries()) {
|
|
9
|
+
const trimmed = part.trim();
|
|
10
|
+
if (trimmed.length === 0) continue;
|
|
11
|
+
const semi = trimmed.indexOf(";");
|
|
12
|
+
const token = (semi === -1 ? trimmed : trimmed.slice(0, semi)).trim().toLowerCase();
|
|
13
|
+
if (token.length === 0) continue;
|
|
14
|
+
let quality = 1;
|
|
15
|
+
if (semi !== -1) {
|
|
16
|
+
let qStr;
|
|
17
|
+
for (const param of trimmed.slice(semi + 1).split(";")) {
|
|
18
|
+
const [name, value] = param.trim().split("=");
|
|
19
|
+
if (name !== "q") continue;
|
|
20
|
+
qStr = value ?? "";
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
if (qStr !== void 0) quality = Number.parseFloat(qStr);
|
|
24
|
+
}
|
|
25
|
+
if (token === "*") {
|
|
26
|
+
if (wildcardQuality === null || Number.isNaN(quality) || Number.isNaN(wildcardQuality) || quality >= wildcardQuality) wildcardQuality = quality;
|
|
27
|
+
} else {
|
|
28
|
+
const currentQuality = qualities.get(token);
|
|
29
|
+
if (currentQuality === void 0 || Number.isNaN(quality) || Number.isNaN(currentQuality) || quality >= currentQuality) {
|
|
30
|
+
qualities.set(token, quality);
|
|
31
|
+
orders.set(token, order);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
qualities,
|
|
37
|
+
orders,
|
|
38
|
+
wildcardQuality
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Return the effective quality for a coding, including wildcard/identity rules. */
|
|
42
|
+
function getEncodingQuality(parsed, encoding) {
|
|
43
|
+
const normalized = encoding.toLowerCase();
|
|
44
|
+
const explicit = parsed.qualities.get(normalized);
|
|
45
|
+
if (explicit !== void 0) return Number.isNaN(explicit) ? 0 : explicit;
|
|
46
|
+
if (normalized === "identity") return parsed.wildcardQuality === 0 ? 0 : 1;
|
|
47
|
+
if (parsed.wildcardQuality !== null) return Number.isNaN(parsed.wildcardQuality) ? 0 : parsed.wildcardQuality;
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
function isEncodingAccepted(parsed, encoding) {
|
|
51
|
+
return getEncodingQuality(parsed, encoding) > 0;
|
|
52
|
+
}
|
|
53
|
+
/** Choose the highest-quality available coding, using array order as the tie-breaker. */
|
|
54
|
+
function selectAcceptedEncoding(parsed, available) {
|
|
55
|
+
let selected = null;
|
|
56
|
+
let selectedQuality = 0;
|
|
57
|
+
for (const encoding of available) {
|
|
58
|
+
const quality = getEncodingQuality(parsed, encoding);
|
|
59
|
+
if (quality > selectedQuality) {
|
|
60
|
+
selected = encoding;
|
|
61
|
+
selectedQuality = quality;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return selected;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Select a content coding while matching Next.js's compression middleware:
|
|
68
|
+
* an explicit identity preference can win, but implicit identity remains a
|
|
69
|
+
* fallback rather than suppressing an otherwise acceptable encoding.
|
|
70
|
+
*/
|
|
71
|
+
function selectContentEncoding(parsed, available) {
|
|
72
|
+
const selected = selectAcceptedEncoding(parsed, available);
|
|
73
|
+
if (selected === null) return "identity";
|
|
74
|
+
const identityQuality = parsed.qualities.get("identity");
|
|
75
|
+
if (identityQuality === void 0 || Number.isNaN(identityQuality)) return selected;
|
|
76
|
+
const selectedQuality = getEncodingQuality(parsed, selected);
|
|
77
|
+
if (identityQuality > selectedQuality) return "identity";
|
|
78
|
+
if (identityQuality < selectedQuality) return selected;
|
|
79
|
+
if (!parsed.qualities.has(selected)) return "identity";
|
|
80
|
+
return (parsed.orders.get("identity") ?? Number.POSITIVE_INFINITY) < (parsed.orders.get(selected) ?? Number.POSITIVE_INFINITY) ? "identity" : selected;
|
|
81
|
+
}
|
|
82
|
+
const HAS_ZSTD = typeof zlib.createZstdCompress === "function";
|
|
83
|
+
/** Select by client q-value first, then zstd > br > gzip > deflate > identity. */
|
|
84
|
+
function negotiateEncoding(req) {
|
|
85
|
+
const accept = req.headers["accept-encoding"];
|
|
86
|
+
if (typeof accept !== "string") return "identity";
|
|
87
|
+
return selectContentEncoding(parseAcceptedEncodings(accept), [
|
|
88
|
+
...HAS_ZSTD ? ["zstd"] : [],
|
|
89
|
+
"br",
|
|
90
|
+
"gzip",
|
|
91
|
+
"deflate"
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { HAS_ZSTD, getEncodingQuality, isEncodingAccepted, negotiateEncoding, parseAcceptedEncodings, selectAcceptedEncoding, selectContentEncoding };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NextI18nConfig } from "../config/next-config.js";
|
|
2
|
+
import { Route } from "../routing/pages-router.js";
|
|
3
|
+
import { ModuleImporter } from "./instrumentation.js";
|
|
4
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
5
|
+
|
|
6
|
+
//#region src/server/api-handler.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Handle an API route request.
|
|
9
|
+
* Returns true if the request was handled, false if no API route matched.
|
|
10
|
+
*/
|
|
11
|
+
declare function handleApiRoute(runner: ModuleImporter, req: IncomingMessage, res: ServerResponse, url: string, apiRoutes: Route[], nextConfig?: {
|
|
12
|
+
basePath?: string;
|
|
13
|
+
i18n?: NextI18nConfig | null;
|
|
14
|
+
trailingSlash?: boolean;
|
|
15
|
+
}): Promise<boolean>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { handleApiRoute };
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { hasBasePath } from "../utils/base-path.js";
|
|
2
|
+
import { matchRoute } from "../routing/pages-router.js";
|
|
3
|
+
import "./server-globals.js";
|
|
4
|
+
import { parseCookieHeader } from "../utils/parse-cookie.js";
|
|
5
|
+
import { NextRequest } from "../shims/server.js";
|
|
6
|
+
import { importModule, reportRequestError } from "./instrumentation.js";
|
|
7
|
+
import { mergeRouteParamsIntoQuery, parseQueryString, urlQueryToSearchParams } from "../utils/query.js";
|
|
8
|
+
import { PagesBodyParseError, getMediaType, isJsonMediaType } from "./pages-media-type.js";
|
|
9
|
+
import { isEdgeApiRuntime } from "./edge-api-runtime.js";
|
|
10
|
+
import { DEFAULT_PAGES_API_BODY_SIZE_LIMIT, resolveBodyParserConfig } from "./pages-body-parser-config.js";
|
|
11
|
+
import { resolveRequestHost, resolveRequestProtocol } from "./proxy-trust.js";
|
|
12
|
+
import { performOnDemandRevalidate } from "./pages-revalidate.js";
|
|
13
|
+
import { decode } from "node:querystring";
|
|
14
|
+
import { Buffer } from "node:buffer";
|
|
15
|
+
//#region src/server/api-handler.ts
|
|
16
|
+
/**
|
|
17
|
+
* Default request body size (1 MB). Matches Next.js default bodyParser sizeLimit.
|
|
18
|
+
* @see https://nextjs.org/docs/pages/building-your-application/routing/api-routes#custom-config
|
|
19
|
+
* Prevents denial-of-service via unbounded request body buffering.
|
|
20
|
+
*/
|
|
21
|
+
const MAX_BODY_SIZE = DEFAULT_PAGES_API_BODY_SIZE_LIMIT;
|
|
22
|
+
/**
|
|
23
|
+
* Parse the request body based on content-type.
|
|
24
|
+
* Enforces a size limit to prevent memory exhaustion attacks.
|
|
25
|
+
*
|
|
26
|
+
* The `sizeLimit` argument honours `export const config = { api: { bodyParser:
|
|
27
|
+
* { sizeLimit: '4mb' } } }` on the route module. To opt out of parsing
|
|
28
|
+
* entirely (`bodyParser: false`), callers must skip this function so the
|
|
29
|
+
* underlying readable stream stays intact on `req` (critical for webhook
|
|
30
|
+
* HMAC signature verification).
|
|
31
|
+
*/
|
|
32
|
+
async function parseBody(req, sizeLimit = MAX_BODY_SIZE) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const chunks = [];
|
|
35
|
+
let totalSize = 0;
|
|
36
|
+
let settled = false;
|
|
37
|
+
req.on("data", (chunk) => {
|
|
38
|
+
totalSize += chunk.length;
|
|
39
|
+
if (totalSize > sizeLimit) {
|
|
40
|
+
settled = true;
|
|
41
|
+
req.destroy();
|
|
42
|
+
reject(new PagesBodyParseError("Request body too large", 413));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
chunks.push(chunk);
|
|
46
|
+
});
|
|
47
|
+
req.on("error", (err) => {
|
|
48
|
+
if (!settled) {
|
|
49
|
+
settled = true;
|
|
50
|
+
reject(err);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
req.on("end", () => {
|
|
54
|
+
if (settled) return;
|
|
55
|
+
settled = true;
|
|
56
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
57
|
+
const mediaType = getMediaType(req.headers["content-type"]);
|
|
58
|
+
if (!raw) {
|
|
59
|
+
resolve(isJsonMediaType(mediaType) ? {} : mediaType === "application/x-www-form-urlencoded" ? decode(raw) : void 0);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (isJsonMediaType(mediaType)) try {
|
|
63
|
+
resolve(JSON.parse(raw));
|
|
64
|
+
} catch {
|
|
65
|
+
reject(new PagesBodyParseError("Invalid JSON", 400));
|
|
66
|
+
}
|
|
67
|
+
else if (mediaType === "application/x-www-form-urlencoded") resolve(decode(raw));
|
|
68
|
+
else resolve(raw);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Parse cookies from the Cookie header.
|
|
74
|
+
*/
|
|
75
|
+
function parseCookies(req) {
|
|
76
|
+
return parseCookieHeader(req.headers.cookie);
|
|
77
|
+
}
|
|
78
|
+
function isEdgeApiRouteModule(module) {
|
|
79
|
+
if (typeof module.default !== "function") return false;
|
|
80
|
+
const bare = module.runtime;
|
|
81
|
+
if (typeof bare === "string") return isEdgeApiRuntime(bare);
|
|
82
|
+
const config = module.config;
|
|
83
|
+
if (!config || typeof config !== "object") return false;
|
|
84
|
+
const runtime = "runtime" in config ? config.runtime : void 0;
|
|
85
|
+
return typeof runtime === "string" && isEdgeApiRuntime(runtime);
|
|
86
|
+
}
|
|
87
|
+
function readEdgeRequestBody(req) {
|
|
88
|
+
if (req.method === "GET" || req.method === "HEAD") return void 0;
|
|
89
|
+
return new ReadableStream({ start(controller) {
|
|
90
|
+
req.on("data", (chunk) => {
|
|
91
|
+
controller.enqueue(typeof chunk === "string" ? Buffer.from(chunk) : new Uint8Array(chunk));
|
|
92
|
+
});
|
|
93
|
+
req.on("end", () => controller.close());
|
|
94
|
+
req.on("error", (error) => controller.error(error));
|
|
95
|
+
} });
|
|
96
|
+
}
|
|
97
|
+
function createEdgeApiRequest(req, url, params, nextConfig) {
|
|
98
|
+
const headers = new Headers();
|
|
99
|
+
for (const [name, value] of Object.entries(req.headers)) {
|
|
100
|
+
if (name.startsWith(":")) continue;
|
|
101
|
+
if (Array.isArray(value)) for (const item of value) headers.append(name, item);
|
|
102
|
+
else if (value !== void 0) headers.set(name, value);
|
|
103
|
+
}
|
|
104
|
+
const proto = resolveRequestProtocol(req);
|
|
105
|
+
const host = resolveRequestHost(req, "localhost");
|
|
106
|
+
const requestUrl = new URL(req.url ?? url, `${proto}://${host}`);
|
|
107
|
+
const basePath = nextConfig?.basePath;
|
|
108
|
+
if (basePath && !hasBasePath(requestUrl.pathname, basePath)) requestUrl.pathname = `${basePath}${requestUrl.pathname}`;
|
|
109
|
+
requestUrl.search = urlQueryToSearchParams(mergeRouteParamsIntoQuery(parseQueryString(url), params)).toString();
|
|
110
|
+
const body = readEdgeRequestBody(req);
|
|
111
|
+
const init = {
|
|
112
|
+
headers,
|
|
113
|
+
method: req.method
|
|
114
|
+
};
|
|
115
|
+
if (body) {
|
|
116
|
+
init.body = body;
|
|
117
|
+
init.duplex = "half";
|
|
118
|
+
}
|
|
119
|
+
return new Request(requestUrl, init);
|
|
120
|
+
}
|
|
121
|
+
function waitForWritableDrain(res) {
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
const cleanup = () => {
|
|
124
|
+
res.off("drain", onDrain);
|
|
125
|
+
res.off("error", onError);
|
|
126
|
+
res.off("close", onClose);
|
|
127
|
+
};
|
|
128
|
+
const onDrain = () => {
|
|
129
|
+
cleanup();
|
|
130
|
+
resolve();
|
|
131
|
+
};
|
|
132
|
+
const onError = (error) => {
|
|
133
|
+
cleanup();
|
|
134
|
+
reject(error);
|
|
135
|
+
};
|
|
136
|
+
const onClose = () => {
|
|
137
|
+
cleanup();
|
|
138
|
+
reject(/* @__PURE__ */ new Error("Response closed before writable drain"));
|
|
139
|
+
};
|
|
140
|
+
res.once("drain", onDrain);
|
|
141
|
+
res.once("error", onError);
|
|
142
|
+
res.once("close", onClose);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async function writeEdgeApiResponseBody(res, body) {
|
|
146
|
+
if (!body) {
|
|
147
|
+
res.end();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const reader = body.getReader();
|
|
151
|
+
try {
|
|
152
|
+
while (true) {
|
|
153
|
+
const result = await reader.read();
|
|
154
|
+
if (result.done) break;
|
|
155
|
+
if (result.value.byteLength === 0) continue;
|
|
156
|
+
if (!res.write(Buffer.from(result.value))) await waitForWritableDrain(res);
|
|
157
|
+
}
|
|
158
|
+
res.end();
|
|
159
|
+
} catch (error) {
|
|
160
|
+
res.destroy(error instanceof Error ? error : new Error(String(error)));
|
|
161
|
+
throw error;
|
|
162
|
+
} finally {
|
|
163
|
+
reader.releaseLock();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Enhance a Node.js req/res pair with Next.js API route helpers.
|
|
168
|
+
*/
|
|
169
|
+
function enhanceApiObjects(req, res, query, body) {
|
|
170
|
+
return {
|
|
171
|
+
apiReq: Object.assign(req, {
|
|
172
|
+
body,
|
|
173
|
+
cookies: parseCookies(req),
|
|
174
|
+
query
|
|
175
|
+
}),
|
|
176
|
+
apiRes: Object.assign(res, {
|
|
177
|
+
status(code) {
|
|
178
|
+
this.statusCode = code;
|
|
179
|
+
return this;
|
|
180
|
+
},
|
|
181
|
+
json(data) {
|
|
182
|
+
this.setHeader("Content-Type", "application/json");
|
|
183
|
+
this.end(JSON.stringify(data));
|
|
184
|
+
},
|
|
185
|
+
send(data) {
|
|
186
|
+
if (Buffer.isBuffer(data)) {
|
|
187
|
+
if (!this.getHeader("Content-Type")) this.setHeader("Content-Type", "application/octet-stream");
|
|
188
|
+
this.setHeader("Content-Length", String(data.length));
|
|
189
|
+
this.end(data);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (typeof data === "object" && data !== null) {
|
|
193
|
+
this.setHeader("Content-Type", "application/json");
|
|
194
|
+
this.end(JSON.stringify(data));
|
|
195
|
+
} else {
|
|
196
|
+
if (!this.getHeader("Content-Type")) this.setHeader("Content-Type", "text/plain");
|
|
197
|
+
this.end(String(data));
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
redirect(statusOrUrl, url) {
|
|
201
|
+
if (typeof statusOrUrl === "string") this.writeHead(307, { Location: statusOrUrl });
|
|
202
|
+
else this.writeHead(statusOrUrl, { Location: url ?? "" });
|
|
203
|
+
this.end();
|
|
204
|
+
},
|
|
205
|
+
async revalidate(urlPath, opts) {
|
|
206
|
+
await performOnDemandRevalidate(req, urlPath, opts);
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Handle an API route request.
|
|
213
|
+
* Returns true if the request was handled, false if no API route matched.
|
|
214
|
+
*/
|
|
215
|
+
async function handleApiRoute(runner, req, res, url, apiRoutes, nextConfig) {
|
|
216
|
+
const match = matchRoute(url, apiRoutes);
|
|
217
|
+
if (!match) return false;
|
|
218
|
+
const { route, params } = match;
|
|
219
|
+
try {
|
|
220
|
+
const apiModule = await importModule(runner, route.filePath);
|
|
221
|
+
if (isEdgeApiRouteModule(apiModule)) {
|
|
222
|
+
const nextRequest = new NextRequest(createEdgeApiRequest(req, url, params, nextConfig), nextConfig ? { nextConfig: {
|
|
223
|
+
basePath: nextConfig.basePath,
|
|
224
|
+
i18n: nextConfig.i18n ?? void 0,
|
|
225
|
+
trailingSlash: nextConfig.trailingSlash
|
|
226
|
+
} } : void 0);
|
|
227
|
+
const response = await apiModule.default(nextRequest);
|
|
228
|
+
if (!(response instanceof Response)) throw new Error("Edge API route did not return a Response");
|
|
229
|
+
res.statusCode = response.status;
|
|
230
|
+
res.statusMessage = response.statusText;
|
|
231
|
+
const setCookieHeaders = response.headers.getSetCookie();
|
|
232
|
+
response.headers.forEach((value, name) => {
|
|
233
|
+
if (name !== "set-cookie") res.setHeader(name, value);
|
|
234
|
+
});
|
|
235
|
+
if (setCookieHeaders.length) res.setHeader("set-cookie", setCookieHeaders);
|
|
236
|
+
await writeEdgeApiResponseBody(res, response.body);
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
const handler = apiModule.default;
|
|
240
|
+
if (typeof handler !== "function") {
|
|
241
|
+
console.error(`[vinext] API route ${route.filePath} does not export a default function`);
|
|
242
|
+
res.statusCode = 500;
|
|
243
|
+
res.end("API route does not export a default function");
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
const query = mergeRouteParamsIntoQuery(parseQueryString(url), params);
|
|
247
|
+
const bodyParserConfig = resolveBodyParserConfig(apiModule.config);
|
|
248
|
+
const { apiReq, apiRes } = enhanceApiObjects(req, res, query, bodyParserConfig.enabled ? await parseBody(req, bodyParserConfig.sizeLimit) : void 0);
|
|
249
|
+
await handler(apiReq, apiRes);
|
|
250
|
+
return true;
|
|
251
|
+
} catch (e) {
|
|
252
|
+
if (e instanceof PagesBodyParseError) {
|
|
253
|
+
res.statusCode = e.statusCode;
|
|
254
|
+
res.statusMessage = e.message;
|
|
255
|
+
res.end(e.message);
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
console.error(e);
|
|
259
|
+
reportRequestError(e instanceof Error ? e : new Error(String(e)), {
|
|
260
|
+
path: url,
|
|
261
|
+
method: req.method ?? "GET",
|
|
262
|
+
headers: Object.fromEntries(Object.entries(req.headers).filter(([k]) => !k.startsWith(":")).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v ?? "")]))
|
|
263
|
+
}, {
|
|
264
|
+
routerKind: "Pages Router",
|
|
265
|
+
routePath: match.route.pattern,
|
|
266
|
+
routeType: "route"
|
|
267
|
+
});
|
|
268
|
+
if (!res.headersSent) {
|
|
269
|
+
res.statusCode = 500;
|
|
270
|
+
res.end("Internal Server Error");
|
|
271
|
+
} else if (!res.writableEnded) res.end();
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
export { handleApiRoute };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "./headers.js";
|
|
2
|
+
//#region src/server/app-action-request.ts
|
|
3
|
+
function isPossibleAppRouteActionRequest(request) {
|
|
4
|
+
if (request.method.toUpperCase() !== "POST") return false;
|
|
5
|
+
const contentType = request.headers.get("content-type");
|
|
6
|
+
return request.headers.has("x-rsc-action") || request.headers.has("next-action") || contentType === "application/x-www-form-urlencoded" || contentType?.startsWith("multipart/form-data") === true;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { isPossibleAppRouteActionRequest };
|