astro 5.16.5 → 6.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{astro.js → bin/astro.mjs} +7 -8
- package/client.d.ts +19 -45
- package/components/ClientRouter.astro +0 -5
- package/components/Code.astro +2 -2
- package/components/Image.astro +2 -2
- package/components/Picture.astro +1 -1
- package/dist/actions/consts.d.ts +2 -5
- package/dist/actions/consts.js +4 -8
- package/dist/actions/integration.js +2 -4
- package/dist/actions/runtime/client.d.ts +84 -3
- package/dist/actions/runtime/client.js +238 -7
- package/dist/actions/runtime/entrypoints/client.d.ts +7 -0
- package/dist/actions/runtime/entrypoints/client.js +91 -0
- package/dist/actions/runtime/entrypoints/route.d.ts +2 -0
- package/dist/actions/runtime/{route.js → entrypoints/route.js} +1 -1
- package/dist/actions/runtime/entrypoints/server.d.ts +6 -0
- package/dist/actions/runtime/entrypoints/server.js +33 -0
- package/dist/actions/runtime/server.d.ts +11 -29
- package/dist/actions/runtime/server.js +162 -82
- package/dist/actions/runtime/types.d.ts +64 -0
- package/dist/actions/runtime/types.js +0 -0
- package/dist/actions/utils.d.ts +2 -2
- package/dist/actions/utils.js +2 -2
- package/dist/actions/vite-plugin-actions.js +18 -21
- package/dist/assets/build/generate.d.ts +2 -2
- package/dist/assets/build/generate.js +11 -9
- package/dist/assets/build/remote.js +4 -14
- package/dist/assets/endpoint/config.js +2 -2
- package/dist/assets/endpoint/dev.js +7 -6
- package/dist/assets/fonts/config.d.ts +86 -174
- package/dist/assets/fonts/config.js +15 -17
- package/dist/assets/fonts/infra/dev-remote-font-provider-mod-resolver.d.ts +3 -3
- package/dist/assets/fonts/infra/dev-remote-font-provider-mod-resolver.js +4 -4
- package/dist/assets/fonts/types.d.ts +1 -1
- package/dist/assets/fonts/vite-plugin-fonts.js +6 -3
- package/dist/assets/services/sharp.js +5 -6
- package/dist/assets/utils/index.d.ts +0 -6
- package/dist/assets/utils/index.js +0 -9
- package/dist/assets/utils/{transformToPath.d.ts → node.d.ts} +15 -1
- package/dist/assets/utils/{node/emitAsset.js → node.js} +34 -56
- package/dist/assets/vite-plugin-assets.js +9 -14
- package/dist/cli/index.js +0 -2
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/cli/preferences/index.js +5 -1
- package/dist/config/index.js +11 -16
- package/dist/container/index.d.ts +0 -1
- package/dist/container/index.js +19 -14
- package/dist/container/pipeline.d.ts +2 -1
- package/dist/container/pipeline.js +4 -11
- package/dist/content/config.d.ts +34 -40
- package/dist/content/config.js +17 -13
- package/dist/content/content-layer.js +14 -21
- package/dist/content/data-store.d.ts +0 -2
- package/dist/content/loaders/errors.d.ts +3 -3
- package/dist/content/loaders/errors.js +5 -2
- package/dist/content/loaders/glob.d.ts +0 -5
- package/dist/content/loaders/glob.js +3 -30
- package/dist/content/loaders/types.d.ts +11 -4
- package/dist/content/mutable-data-store.js +1 -14
- package/dist/content/runtime-assets.d.ts +4 -4
- package/dist/content/runtime-assets.js +4 -7
- package/dist/content/runtime.d.ts +35 -73
- package/dist/content/runtime.js +63 -231
- package/dist/content/server-listeners.js +25 -88
- package/dist/content/types-generator.d.ts +1 -6
- package/dist/content/types-generator.js +87 -156
- package/dist/content/utils.d.ts +47 -412
- package/dist/content/utils.js +88 -203
- package/dist/content/vite-plugin-content-assets.d.ts +12 -4
- package/dist/content/vite-plugin-content-assets.js +100 -56
- package/dist/content/vite-plugin-content-imports.js +10 -8
- package/dist/content/vite-plugin-content-virtual-mod.js +13 -131
- package/dist/core/app/app.d.ts +5 -0
- package/dist/core/app/app.js +13 -0
- package/dist/core/app/base.d.ts +132 -0
- package/dist/core/app/base.js +448 -0
- package/dist/core/app/common.d.ts +6 -2
- package/dist/core/app/common.js +60 -33
- package/dist/core/app/dev/app.d.ts +15 -0
- package/dist/core/app/dev/app.js +86 -0
- package/dist/core/app/dev/pipeline.d.ts +13 -0
- package/dist/core/app/dev/pipeline.js +123 -0
- package/dist/core/app/entrypoint.d.ts +2 -0
- package/dist/core/app/entrypoint.js +15 -0
- package/dist/core/app/index.d.ts +7 -114
- package/dist/core/app/index.js +20 -557
- package/dist/core/app/logging.d.ts +3 -0
- package/dist/core/app/logging.js +11 -0
- package/dist/core/app/manifest.d.ts +9 -0
- package/dist/core/app/manifest.js +107 -0
- package/dist/core/app/middlewares.js +1 -1
- package/dist/core/app/node.d.ts +2 -8
- package/dist/core/app/node.js +8 -9
- package/dist/core/app/pipeline.d.ts +6 -5
- package/dist/core/app/pipeline.js +65 -49
- package/dist/core/app/types.d.ts +58 -22
- package/dist/core/app/validate-forwarded-headers.d.ts +16 -0
- package/dist/core/app/validate-forwarded-headers.js +60 -0
- package/dist/core/base-pipeline.d.ts +22 -14
- package/dist/core/base-pipeline.js +54 -6
- package/dist/core/build/app.d.ts +13 -0
- package/dist/core/build/app.js +38 -0
- package/dist/core/build/common.d.ts +1 -1
- package/dist/core/build/common.js +2 -2
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +95 -204
- package/dist/core/build/graph.js +2 -2
- package/dist/core/build/index.js +11 -19
- package/dist/core/build/internal.d.ts +3 -29
- package/dist/core/build/internal.js +1 -45
- package/dist/core/build/pipeline.d.ts +15 -26
- package/dist/core/build/pipeline.js +106 -170
- package/dist/core/build/plugins/index.d.ts +4 -2
- package/dist/core/build/plugins/index.js +17 -23
- package/dist/core/build/plugins/plugin-analyzer.d.ts +2 -2
- package/dist/core/build/plugins/plugin-analyzer.js +5 -13
- package/dist/core/build/plugins/plugin-component-entry.d.ts +7 -2
- package/dist/core/build/plugins/plugin-component-entry.js +5 -13
- package/dist/core/build/plugins/plugin-css.d.ts +2 -2
- package/dist/core/build/plugins/plugin-css.js +86 -41
- package/dist/core/build/plugins/plugin-internals.d.ts +2 -2
- package/dist/core/build/plugins/plugin-internals.js +24 -18
- package/dist/core/build/plugins/plugin-manifest.d.ts +33 -5
- package/dist/core/build/plugins/plugin-manifest.js +89 -131
- package/dist/core/build/plugins/plugin-middleware.d.ts +2 -2
- package/dist/core/build/plugins/plugin-middleware.js +5 -7
- package/dist/core/build/plugins/plugin-noop.d.ts +3 -0
- package/dist/core/build/plugins/plugin-noop.js +29 -0
- package/dist/core/build/plugins/plugin-prerender.d.ts +2 -2
- package/dist/core/build/plugins/plugin-prerender.js +7 -64
- package/dist/core/build/plugins/plugin-scripts.d.ts +5 -2
- package/dist/core/build/plugins/plugin-scripts.js +5 -13
- package/dist/core/build/plugins/plugin-ssr.d.ts +2 -2
- package/dist/core/build/plugins/plugin-ssr.js +60 -132
- package/dist/core/build/plugins/util.d.ts +1 -25
- package/dist/core/build/plugins/util.js +0 -47
- package/dist/core/build/runtime.d.ts +26 -0
- package/dist/core/build/runtime.js +45 -0
- package/dist/core/build/static-build.d.ts +2 -2
- package/dist/core/build/static-build.js +180 -154
- package/dist/core/build/types.d.ts +1 -2
- package/dist/core/build/util.d.ts +0 -1
- package/dist/core/build/util.js +0 -7
- package/dist/core/compile/compile.d.ts +2 -3
- package/dist/core/compile/compile.js +2 -4
- package/dist/core/config/config.js +2 -2
- package/dist/core/config/index.d.ts +0 -1
- package/dist/core/config/index.js +0 -2
- package/dist/core/config/schemas/base.d.ts +330 -1463
- package/dist/core/config/schemas/base.js +40 -56
- package/dist/core/config/schemas/refined.d.ts +2 -2
- package/dist/core/config/schemas/refined.js +8 -1
- package/dist/core/config/schemas/relative.d.ts +607 -1737
- package/dist/core/config/schemas/relative.js +4 -4
- package/dist/core/config/settings.d.ts +3 -3
- package/dist/core/config/settings.js +5 -6
- package/dist/core/config/validate.js +13 -2
- package/dist/core/config/vite-load.js +12 -3
- package/dist/core/constants.d.ts +12 -0
- package/dist/core/constants.js +22 -1
- package/dist/core/create-vite.d.ts +2 -6
- package/dist/core/create-vite.js +36 -47
- package/dist/core/csp/common.d.ts +1 -1
- package/dist/core/csp/common.js +1 -1
- package/dist/core/csp/config.d.ts +8 -4
- package/dist/core/csp/config.js +1 -1
- package/dist/core/dev/container.js +13 -9
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +15 -6
- package/dist/core/errors/dev/runtime.d.ts +6 -0
- package/dist/core/errors/dev/runtime.js +27 -0
- package/dist/core/errors/dev/vite.js +2 -19
- package/dist/core/errors/errors-data.d.ts +85 -57
- package/dist/core/errors/errors-data.js +40 -28
- package/dist/core/errors/errors.d.ts +3 -3
- package/dist/core/errors/errors.js +1 -1
- package/dist/core/errors/overlay.js +1 -1
- package/dist/core/errors/zod-error-map.d.ts +2 -2
- package/dist/core/errors/zod-error-map.js +26 -24
- package/dist/core/messages.d.ts +2 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.js +1 -1
- package/dist/core/middleware/defineMiddleware.d.ts +2 -0
- package/dist/core/middleware/defineMiddleware.js +6 -0
- package/dist/core/middleware/index.d.ts +4 -4
- package/dist/core/middleware/index.js +6 -12
- package/dist/core/middleware/sequence.js +4 -4
- package/dist/core/middleware/vite-plugin.d.ts +1 -1
- package/dist/core/middleware/vite-plugin.js +18 -7
- package/dist/core/module-loader/index.d.ts +2 -2
- package/dist/core/module-loader/index.js +1 -1
- package/dist/core/module-loader/{loader.d.ts → runner.d.ts} +6 -17
- package/dist/core/module-loader/{loader.js → runner.js} +3 -0
- package/dist/core/module-loader/vite.d.ts +3 -2
- package/dist/core/module-loader/vite.js +17 -13
- package/dist/core/preview/index.js +20 -5
- package/dist/core/preview/static-preview-server.js +1 -0
- package/dist/core/redirects/component.js +1 -2
- package/dist/core/redirects/index.d.ts +0 -1
- package/dist/core/redirects/index.js +1 -3
- package/dist/core/redirects/render.js +5 -2
- package/dist/core/render/paginate.d.ts +1 -1
- package/dist/core/render/paginate.js +8 -6
- package/dist/core/render/params-and-props.d.ts +2 -0
- package/dist/core/render/params-and-props.js +19 -7
- package/dist/core/render/route-cache.d.ts +3 -3
- package/dist/core/render/route-cache.js +7 -7
- package/dist/core/render-context.d.ts +9 -7
- package/dist/core/render-context.js +46 -47
- package/dist/core/routing/astro-designed-error-pages.js +2 -2
- package/dist/core/routing/default.js +1 -1
- package/dist/core/routing/helpers.d.ts +22 -0
- package/dist/core/routing/helpers.js +25 -0
- package/dist/core/routing/index.d.ts +1 -1
- package/dist/core/routing/index.js +2 -2
- package/dist/core/routing/manifest/create.d.ts +6 -1
- package/dist/core/routing/manifest/create.js +9 -13
- package/dist/core/routing/manifest/generator.d.ts +3 -1
- package/dist/core/routing/params.d.ts +2 -1
- package/dist/core/routing/params.js +8 -8
- package/dist/core/routing/validation.d.ts +1 -2
- package/dist/core/routing/validation.js +2 -18
- package/dist/core/server-islands/endpoint.d.ts +1 -2
- package/dist/core/server-islands/endpoint.js +5 -4
- package/dist/core/server-islands/vite-plugin-server-islands.d.ts +1 -1
- package/dist/core/server-islands/vite-plugin-server-islands.js +89 -44
- package/dist/core/session/vite-plugin.d.ts +6 -0
- package/dist/core/session/vite-plugin.js +53 -0
- package/dist/core/session.d.ts +4 -2
- package/dist/core/session.js +8 -48
- package/dist/core/sync/index.d.ts +2 -5
- package/dist/core/sync/index.js +19 -34
- package/dist/core/util.d.ts +2 -2
- package/dist/core/util.js +3 -3
- package/dist/entrypoints/legacy.d.ts +2 -0
- package/dist/entrypoints/legacy.js +12 -0
- package/dist/entrypoints/prerender.d.ts +4 -0
- package/dist/entrypoints/prerender.js +7 -0
- package/dist/env/env-loader.d.ts +0 -1
- package/dist/env/env-loader.js +4 -17
- package/dist/env/schema.d.ts +21 -251
- package/dist/env/schema.js +6 -3
- package/dist/env/vite-plugin-env.js +3 -2
- package/dist/env/vite-plugin-import-meta-env.js +3 -2
- package/dist/environments.d.ts +3 -0
- package/dist/environments.js +11 -0
- package/dist/events/error.d.ts +2 -2
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.js +0 -3
- package/dist/i18n/utils.d.ts +1 -6
- package/dist/i18n/utils.js +1 -63
- package/dist/i18n/vite-plugin-i18n.d.ts +0 -5
- package/dist/i18n/vite-plugin-i18n.js +1 -22
- package/dist/integrations/hooks.d.ts +2 -3
- package/dist/integrations/hooks.js +9 -33
- package/dist/manifest/serialized.d.ts +9 -0
- package/dist/manifest/serialized.js +144 -0
- package/dist/manifest/virtual-module.d.ts +1 -4
- package/dist/manifest/virtual-module.js +77 -80
- package/dist/preferences/index.d.ts +1 -2
- package/dist/prefetch/index.d.ts +0 -10
- package/dist/prefetch/index.js +1 -1
- package/dist/prerender/routing.d.ts +5 -7
- package/dist/prerender/routing.js +6 -17
- package/dist/runtime/server/astro-global.d.ts +2 -2
- package/dist/runtime/server/astro-global.js +86 -24
- package/dist/runtime/server/render/server-islands.js +2 -2
- package/dist/runtime/server/transition.d.ts +1 -0
- package/dist/transitions/events.d.ts +7 -0
- package/dist/transitions/router.js +7 -3
- package/dist/transitions/vite-plugin-transitions.js +1 -4
- package/dist/types/astro.d.ts +10 -8
- package/dist/types/public/common.d.ts +1 -3
- package/dist/types/public/config.d.ts +364 -415
- package/dist/types/public/context.d.ts +21 -52
- package/dist/types/public/index.d.ts +2 -1
- package/dist/types/public/integrations.d.ts +23 -18
- package/dist/types/public/internal.d.ts +3 -18
- package/dist/types/public/preview.d.ts +6 -0
- package/dist/virtual-modules/i18n.d.ts +10 -2
- package/dist/virtual-modules/i18n.js +16 -7
- package/dist/virtual-modules/live-config.d.ts +1 -3
- package/dist/virtual-modules/live-config.js +1 -5
- package/dist/virtual-modules/middleware.d.ts +2 -1
- package/dist/virtual-modules/middleware.js +2 -1
- package/dist/vite-plugin-adapter-config/index.js +3 -2
- package/dist/vite-plugin-app/app.d.ts +47 -0
- package/dist/vite-plugin-app/app.js +410 -0
- package/dist/vite-plugin-app/createAstroServerApp.d.ts +8 -0
- package/dist/vite-plugin-app/createAstroServerApp.js +56 -0
- package/dist/vite-plugin-app/index.d.ts +3 -0
- package/dist/vite-plugin-app/index.js +16 -0
- package/dist/{vite-plugin-astro-server → vite-plugin-app}/pipeline.d.ts +5 -7
- package/dist/vite-plugin-app/pipeline.js +166 -0
- package/dist/vite-plugin-astro/index.js +11 -13
- package/dist/vite-plugin-astro-server/controller.d.ts +1 -1
- package/dist/vite-plugin-astro-server/error.d.ts +3 -4
- package/dist/vite-plugin-astro-server/error.js +2 -5
- package/dist/vite-plugin-astro-server/index.d.ts +1 -2
- package/dist/vite-plugin-astro-server/index.js +6 -4
- package/dist/vite-plugin-astro-server/metadata.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.d.ts +4 -7
- package/dist/vite-plugin-astro-server/plugin.js +53 -96
- package/dist/vite-plugin-astro-server/server-state.d.ts +1 -1
- package/dist/vite-plugin-astro-server/util.d.ts +0 -2
- package/dist/vite-plugin-astro-server/util.js +1 -2
- package/dist/vite-plugin-astro-server/vite.d.ts +2 -2
- package/dist/vite-plugin-astro-server/vite.js +7 -7
- package/dist/vite-plugin-config-alias/index.js +40 -32
- package/dist/vite-plugin-css/index.d.ts +18 -0
- package/dist/vite-plugin-css/index.js +134 -0
- package/dist/vite-plugin-css/util.d.ts +5 -0
- package/dist/vite-plugin-css/util.js +8 -0
- package/dist/vite-plugin-environment/index.d.ts +15 -0
- package/dist/vite-plugin-environment/index.js +77 -0
- package/dist/vite-plugin-head/index.d.ts +1 -2
- package/dist/vite-plugin-head/index.js +42 -58
- package/dist/vite-plugin-hmr-reload/index.js +2 -1
- package/dist/vite-plugin-markdown/index.js +0 -1
- package/dist/vite-plugin-pages/const.d.ts +2 -0
- package/dist/vite-plugin-pages/const.js +6 -0
- package/dist/vite-plugin-pages/index.d.ts +2 -0
- package/dist/vite-plugin-pages/index.js +7 -0
- package/dist/vite-plugin-pages/page.d.ts +7 -0
- package/dist/vite-plugin-pages/page.js +48 -0
- package/dist/vite-plugin-pages/pages.d.ts +8 -0
- package/dist/vite-plugin-pages/pages.js +57 -0
- package/dist/vite-plugin-pages/util.d.ts +8 -0
- package/dist/vite-plugin-pages/util.js +15 -0
- package/dist/vite-plugin-renderers/index.d.ts +9 -0
- package/dist/vite-plugin-renderers/index.js +40 -0
- package/dist/vite-plugin-routes/index.d.ts +14 -0
- package/dist/vite-plugin-routes/index.js +177 -0
- package/dist/vite-plugin-scripts/index.js +2 -6
- package/dist/vite-plugin-scripts/page-ssr.js +3 -2
- package/dist/zod.d.ts +2 -2
- package/dist/zod.js +2 -2
- package/package.json +14 -15
- package/templates/content/module.mjs +9 -63
- package/templates/content/types.d.ts +32 -78
- package/types/actions.d.ts +1 -5
- package/types/content.d.ts +9 -11
- package/types/transitions.d.ts +25 -0
- package/dist/actions/loadActions.d.ts +0 -8
- package/dist/actions/loadActions.js +0 -13
- package/dist/actions/runtime/route.d.ts +0 -2
- package/dist/actions/runtime/shared.d.ts +0 -60
- package/dist/actions/runtime/shared.js +0 -296
- package/dist/actions/runtime/utils.d.ts +0 -31
- package/dist/actions/runtime/utils.js +0 -16
- package/dist/actions/runtime/virtual.d.ts +0 -4
- package/dist/actions/runtime/virtual.js +0 -127
- package/dist/assets/utils/node/emitAsset.d.ts +0 -29
- package/dist/assets/utils/transformToPath.js +0 -32
- package/dist/config/vite-plugin-content-listen.d.ts +0 -17
- package/dist/config/vite-plugin-content-listen.js +0 -26
- package/dist/container/polyfill.d.ts +0 -1
- package/dist/container/polyfill.js +0 -2
- package/dist/core/build/css-asset-name.d.ts +0 -9
- package/dist/core/build/css-asset-name.js +0 -89
- package/dist/core/build/plugin.d.ts +0 -43
- package/dist/core/build/plugin.js +0 -61
- package/dist/core/build/plugins/plugin-actions.d.ts +0 -4
- package/dist/core/build/plugins/plugin-actions.js +0 -16
- package/dist/core/build/plugins/plugin-chunks.d.ts +0 -2
- package/dist/core/build/plugins/plugin-chunks.js +0 -33
- package/dist/core/build/plugins/plugin-pages.d.ts +0 -6
- package/dist/core/build/plugins/plugin-pages.js +0 -66
- package/dist/core/build/plugins/plugin-renderers.d.ts +0 -5
- package/dist/core/build/plugins/plugin-renderers.js +0 -54
- package/dist/core/middleware/loadMiddleware.d.ts +0 -7
- package/dist/core/middleware/loadMiddleware.js +0 -14
- package/dist/core/polyfill.d.ts +0 -5
- package/dist/core/polyfill.js +0 -17
- package/dist/core/redirects/helpers.d.ts +0 -7
- package/dist/core/redirects/helpers.js +0 -10
- package/dist/core/routing/manifest/serialization.d.ts +0 -5
- package/dist/core/routing/manifest/serialization.js +0 -37
- package/dist/prerender/metadata.d.ts +0 -8
- package/dist/prerender/metadata.js +0 -18
- package/dist/vite-plugin-astro-postprocess/index.d.ts +0 -2
- package/dist/vite-plugin-astro-postprocess/index.js +0 -48
- package/dist/vite-plugin-astro-server/css.d.ts +0 -13
- package/dist/vite-plugin-astro-server/css.js +0 -48
- package/dist/vite-plugin-astro-server/pipeline.js +0 -166
- package/dist/vite-plugin-astro-server/request.d.ts +0 -14
- package/dist/vite-plugin-astro-server/request.js +0 -73
- package/dist/vite-plugin-astro-server/route.d.ts +0 -25
- package/dist/vite-plugin-astro-server/route.js +0 -283
- package/dist/vite-plugin-scanner/index.d.ts +0 -10
- package/dist/vite-plugin-scanner/index.js +0 -87
- package/dist/vite-plugin-ssr-manifest/index.d.ts +0 -2
- package/dist/vite-plugin-ssr-manifest/index.js +0 -26
package/dist/core/app/index.js
CHANGED
|
@@ -1,562 +1,25 @@
|
|
|
1
|
+
import { App } from "./app.js";
|
|
2
|
+
import { BaseApp } from "./base.js";
|
|
3
|
+
import { fromRoutingStrategy, toRoutingStrategy } from "./common.js";
|
|
4
|
+
import { createConsoleLogger } from "./logging.js";
|
|
1
5
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
clientAddressSymbol,
|
|
10
|
-
DEFAULT_404_COMPONENT,
|
|
11
|
-
REROUTABLE_STATUS_CODES,
|
|
12
|
-
REROUTE_DIRECTIVE_HEADER,
|
|
13
|
-
responseSentSymbol
|
|
14
|
-
} from "../constants.js";
|
|
15
|
-
import { getSetCookiesFromResponse } from "../cookies/index.js";
|
|
16
|
-
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
17
|
-
import { consoleLogDestination } from "../logger/console.js";
|
|
18
|
-
import { AstroIntegrationLogger, Logger } from "../logger/core.js";
|
|
19
|
-
import { NOOP_MIDDLEWARE_FN } from "../middleware/noop-middleware.js";
|
|
20
|
-
import {
|
|
21
|
-
appendForwardSlash,
|
|
22
|
-
joinPaths,
|
|
23
|
-
prependForwardSlash,
|
|
24
|
-
removeTrailingForwardSlash
|
|
25
|
-
} from "../path.js";
|
|
26
|
-
import { createAssetLink } from "../render/ssr-element.js";
|
|
27
|
-
import { RenderContext } from "../render-context.js";
|
|
28
|
-
import { redirectTemplate } from "../routing/3xx.js";
|
|
29
|
-
import { ensure404Route } from "../routing/astro-designed-error-pages.js";
|
|
30
|
-
import { createDefaultRoutes } from "../routing/default.js";
|
|
31
|
-
import { matchRoute } from "../routing/match.js";
|
|
32
|
-
import { PERSIST_SYMBOL } from "../session.js";
|
|
33
|
-
import { validateAndDecodePathname } from "../util/pathname.js";
|
|
6
|
+
deserializeManifest,
|
|
7
|
+
deserializeRouteData,
|
|
8
|
+
deserializeRouteInfo,
|
|
9
|
+
serializeRouteData,
|
|
10
|
+
serializeRouteInfo
|
|
11
|
+
} from "./manifest.js";
|
|
34
12
|
import { AppPipeline } from "./pipeline.js";
|
|
35
|
-
import { deserializeManifest } from "./common.js";
|
|
36
|
-
class App {
|
|
37
|
-
#manifest;
|
|
38
|
-
#manifestData;
|
|
39
|
-
#logger = new Logger({
|
|
40
|
-
dest: consoleLogDestination,
|
|
41
|
-
level: "info"
|
|
42
|
-
});
|
|
43
|
-
#baseWithoutTrailingSlash;
|
|
44
|
-
#pipeline;
|
|
45
|
-
#adapterLogger;
|
|
46
|
-
constructor(manifest, streaming = true) {
|
|
47
|
-
this.#manifest = manifest;
|
|
48
|
-
this.#manifestData = {
|
|
49
|
-
routes: manifest.routes.map((route) => route.routeData)
|
|
50
|
-
};
|
|
51
|
-
ensure404Route(this.#manifestData);
|
|
52
|
-
this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base);
|
|
53
|
-
this.#pipeline = this.#createPipeline(streaming);
|
|
54
|
-
this.#adapterLogger = new AstroIntegrationLogger(
|
|
55
|
-
this.#logger.options,
|
|
56
|
-
this.#manifest.adapterName
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
getAdapterLogger() {
|
|
60
|
-
return this.#adapterLogger;
|
|
61
|
-
}
|
|
62
|
-
getAllowedDomains() {
|
|
63
|
-
return this.#manifest.allowedDomains;
|
|
64
|
-
}
|
|
65
|
-
get manifest() {
|
|
66
|
-
return this.#manifest;
|
|
67
|
-
}
|
|
68
|
-
set manifest(value) {
|
|
69
|
-
this.#manifest = value;
|
|
70
|
-
}
|
|
71
|
-
matchesAllowedDomains(forwardedHost, protocol) {
|
|
72
|
-
return App.validateForwardedHost(forwardedHost, this.#manifest.allowedDomains, protocol);
|
|
73
|
-
}
|
|
74
|
-
static validateForwardedHost(forwardedHost, allowedDomains, protocol) {
|
|
75
|
-
if (!allowedDomains || allowedDomains.length === 0) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
const testUrl = new URL(`${protocol || "https"}://${forwardedHost}`);
|
|
80
|
-
return allowedDomains.some((pattern) => {
|
|
81
|
-
return matchPattern(testUrl, pattern);
|
|
82
|
-
});
|
|
83
|
-
} catch {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Validate a hostname by rejecting any with path separators.
|
|
89
|
-
* Prevents path injection attacks. Invalid hostnames return undefined.
|
|
90
|
-
*/
|
|
91
|
-
static sanitizeHost(hostname) {
|
|
92
|
-
if (!hostname) return void 0;
|
|
93
|
-
if (/[/\\]/.test(hostname)) return void 0;
|
|
94
|
-
return hostname;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Validate forwarded headers (proto, host, port) against allowedDomains.
|
|
98
|
-
* Returns validated values or undefined for rejected headers.
|
|
99
|
-
* Uses strict defaults: http/https only for proto, rejects port if not in allowedDomains.
|
|
100
|
-
*/
|
|
101
|
-
static validateForwardedHeaders(forwardedProtocol, forwardedHost, forwardedPort, allowedDomains) {
|
|
102
|
-
const result = {};
|
|
103
|
-
if (forwardedProtocol) {
|
|
104
|
-
if (allowedDomains && allowedDomains.length > 0) {
|
|
105
|
-
const hasProtocolPatterns = allowedDomains.some(
|
|
106
|
-
(pattern) => pattern.protocol !== void 0
|
|
107
|
-
);
|
|
108
|
-
if (hasProtocolPatterns) {
|
|
109
|
-
try {
|
|
110
|
-
const testUrl = new URL(`${forwardedProtocol}://example.com`);
|
|
111
|
-
const isAllowed = allowedDomains.some((pattern) => matchPattern(testUrl, pattern));
|
|
112
|
-
if (isAllowed) {
|
|
113
|
-
result.protocol = forwardedProtocol;
|
|
114
|
-
}
|
|
115
|
-
} catch {
|
|
116
|
-
}
|
|
117
|
-
} else if (/^https?$/.test(forwardedProtocol)) {
|
|
118
|
-
result.protocol = forwardedProtocol;
|
|
119
|
-
}
|
|
120
|
-
} else if (/^https?$/.test(forwardedProtocol)) {
|
|
121
|
-
result.protocol = forwardedProtocol;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (forwardedPort && allowedDomains && allowedDomains.length > 0) {
|
|
125
|
-
const hasPortPatterns = allowedDomains.some((pattern) => pattern.port !== void 0);
|
|
126
|
-
if (hasPortPatterns) {
|
|
127
|
-
const isAllowed = allowedDomains.some((pattern) => pattern.port === forwardedPort);
|
|
128
|
-
if (isAllowed) {
|
|
129
|
-
result.port = forwardedPort;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (forwardedHost && forwardedHost.length > 0 && allowedDomains && allowedDomains.length > 0) {
|
|
134
|
-
const protoForValidation = result.protocol || "https";
|
|
135
|
-
const sanitized = App.sanitizeHost(forwardedHost);
|
|
136
|
-
if (sanitized) {
|
|
137
|
-
try {
|
|
138
|
-
const hostnameOnly = sanitized.split(":")[0];
|
|
139
|
-
const portFromHost = sanitized.includes(":") ? sanitized.split(":")[1] : void 0;
|
|
140
|
-
const portForValidation = result.port || portFromHost;
|
|
141
|
-
const hostWithPort = portForValidation ? `${hostnameOnly}:${portForValidation}` : hostnameOnly;
|
|
142
|
-
const testUrl = new URL(`${protoForValidation}://${hostWithPort}`);
|
|
143
|
-
const isAllowed = allowedDomains.some((pattern) => matchPattern(testUrl, pattern));
|
|
144
|
-
if (isAllowed) {
|
|
145
|
-
result.host = sanitized;
|
|
146
|
-
}
|
|
147
|
-
} catch {
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Creates a pipeline by reading the stored manifest
|
|
155
|
-
*
|
|
156
|
-
* @param streaming
|
|
157
|
-
* @private
|
|
158
|
-
*/
|
|
159
|
-
#createPipeline(streaming = false) {
|
|
160
|
-
return AppPipeline.create({
|
|
161
|
-
logger: this.#logger,
|
|
162
|
-
manifest: this.#manifest,
|
|
163
|
-
runtimeMode: "production",
|
|
164
|
-
renderers: this.#manifest.renderers,
|
|
165
|
-
defaultRoutes: createDefaultRoutes(this.#manifest),
|
|
166
|
-
resolve: async (specifier) => {
|
|
167
|
-
if (!(specifier in this.#manifest.entryModules)) {
|
|
168
|
-
throw new Error(`Unable to resolve [${specifier}]`);
|
|
169
|
-
}
|
|
170
|
-
const bundlePath = this.#manifest.entryModules[specifier];
|
|
171
|
-
if (bundlePath.startsWith("data:") || bundlePath.length === 0) {
|
|
172
|
-
return bundlePath;
|
|
173
|
-
} else {
|
|
174
|
-
return createAssetLink(bundlePath, this.#manifest.base, this.#manifest.assetsPrefix);
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
serverLike: true,
|
|
178
|
-
streaming
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
set setManifestData(newManifestData) {
|
|
182
|
-
this.#manifestData = newManifestData;
|
|
183
|
-
}
|
|
184
|
-
removeBase(pathname) {
|
|
185
|
-
if (pathname.startsWith(this.#manifest.base)) {
|
|
186
|
-
return pathname.slice(this.#baseWithoutTrailingSlash.length + 1);
|
|
187
|
-
}
|
|
188
|
-
return pathname;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* It removes the base from the request URL, prepends it with a forward slash and attempts to decoded it.
|
|
192
|
-
*
|
|
193
|
-
* If the decoding fails, it logs the error and return the pathname as is.
|
|
194
|
-
* @param request
|
|
195
|
-
* @private
|
|
196
|
-
*/
|
|
197
|
-
#getPathnameFromRequest(request) {
|
|
198
|
-
const url = new URL(request.url);
|
|
199
|
-
const pathname = prependForwardSlash(this.removeBase(url.pathname));
|
|
200
|
-
try {
|
|
201
|
-
return validateAndDecodePathname(pathname);
|
|
202
|
-
} catch (e) {
|
|
203
|
-
this.getAdapterLogger().error(e.toString());
|
|
204
|
-
return pathname;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Given a `Request`, it returns the `RouteData` that matches its `pathname`. By default, prerendered
|
|
209
|
-
* routes aren't returned, even if they are matched.
|
|
210
|
-
*
|
|
211
|
-
* When `allowPrerenderedRoutes` is `true`, the function returns matched prerendered routes too.
|
|
212
|
-
* @param request
|
|
213
|
-
* @param allowPrerenderedRoutes
|
|
214
|
-
*/
|
|
215
|
-
match(request, allowPrerenderedRoutes = false) {
|
|
216
|
-
const url = new URL(request.url);
|
|
217
|
-
if (this.#manifest.assets.has(url.pathname)) return void 0;
|
|
218
|
-
let pathname = this.#computePathnameFromDomain(request);
|
|
219
|
-
if (!pathname) {
|
|
220
|
-
pathname = prependForwardSlash(this.removeBase(url.pathname));
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
pathname = validateAndDecodePathname(pathname);
|
|
224
|
-
} catch {
|
|
225
|
-
return void 0;
|
|
226
|
-
}
|
|
227
|
-
let routeData = matchRoute(pathname, this.#manifestData);
|
|
228
|
-
if (!routeData) return void 0;
|
|
229
|
-
if (allowPrerenderedRoutes) {
|
|
230
|
-
return routeData;
|
|
231
|
-
} else if (routeData.prerender) {
|
|
232
|
-
return void 0;
|
|
233
|
-
}
|
|
234
|
-
return routeData;
|
|
235
|
-
}
|
|
236
|
-
#computePathnameFromDomain(request) {
|
|
237
|
-
let pathname = void 0;
|
|
238
|
-
const url = new URL(request.url);
|
|
239
|
-
if (this.#manifest.i18n && (this.#manifest.i18n.strategy === "domains-prefix-always" || this.#manifest.i18n.strategy === "domains-prefix-other-locales" || this.#manifest.i18n.strategy === "domains-prefix-always-no-redirect")) {
|
|
240
|
-
const validated = App.validateForwardedHeaders(
|
|
241
|
-
request.headers.get("X-Forwarded-Proto") ?? void 0,
|
|
242
|
-
request.headers.get("X-Forwarded-Host") ?? void 0,
|
|
243
|
-
request.headers.get("X-Forwarded-Port") ?? void 0,
|
|
244
|
-
this.#manifest.allowedDomains
|
|
245
|
-
);
|
|
246
|
-
let protocol = validated.protocol ? validated.protocol + ":" : url.protocol;
|
|
247
|
-
let host = validated.host ?? request.headers.get("Host");
|
|
248
|
-
if (host && protocol) {
|
|
249
|
-
host = host.split(":")[0];
|
|
250
|
-
try {
|
|
251
|
-
let locale;
|
|
252
|
-
const hostAsUrl = new URL(`${protocol}//${host}`);
|
|
253
|
-
for (const [domainKey, localeValue] of Object.entries(
|
|
254
|
-
this.#manifest.i18n.domainLookupTable
|
|
255
|
-
)) {
|
|
256
|
-
const domainKeyAsUrl = new URL(domainKey);
|
|
257
|
-
if (hostAsUrl.host === domainKeyAsUrl.host && hostAsUrl.protocol === domainKeyAsUrl.protocol) {
|
|
258
|
-
locale = localeValue;
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (locale) {
|
|
263
|
-
pathname = prependForwardSlash(
|
|
264
|
-
joinPaths(normalizeTheLocale(locale), this.removeBase(url.pathname))
|
|
265
|
-
);
|
|
266
|
-
if (url.pathname.endsWith("/")) {
|
|
267
|
-
pathname = appendForwardSlash(pathname);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
} catch (e) {
|
|
271
|
-
this.#logger.error(
|
|
272
|
-
"router",
|
|
273
|
-
`Astro tried to parse ${protocol}//${host} as an URL, but it threw a parsing error. Check the X-Forwarded-Host and X-Forwarded-Proto headers.`
|
|
274
|
-
);
|
|
275
|
-
this.#logger.error("router", `Error: ${e}`);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return pathname;
|
|
280
|
-
}
|
|
281
|
-
#redirectTrailingSlash(pathname) {
|
|
282
|
-
const { trailingSlash } = this.#manifest;
|
|
283
|
-
if (pathname === "/" || isInternalPath(pathname)) {
|
|
284
|
-
return pathname;
|
|
285
|
-
}
|
|
286
|
-
const path = collapseDuplicateTrailingSlashes(pathname, trailingSlash !== "never");
|
|
287
|
-
if (path !== pathname) {
|
|
288
|
-
return path;
|
|
289
|
-
}
|
|
290
|
-
if (trailingSlash === "ignore") {
|
|
291
|
-
return pathname;
|
|
292
|
-
}
|
|
293
|
-
if (trailingSlash === "always" && !hasFileExtension(pathname)) {
|
|
294
|
-
return appendForwardSlash(pathname);
|
|
295
|
-
}
|
|
296
|
-
if (trailingSlash === "never") {
|
|
297
|
-
return removeTrailingForwardSlash(pathname);
|
|
298
|
-
}
|
|
299
|
-
return pathname;
|
|
300
|
-
}
|
|
301
|
-
async render(request, renderOptions) {
|
|
302
|
-
let routeData;
|
|
303
|
-
let locals;
|
|
304
|
-
let clientAddress;
|
|
305
|
-
let addCookieHeader;
|
|
306
|
-
const url = new URL(request.url);
|
|
307
|
-
const redirect = this.#redirectTrailingSlash(url.pathname);
|
|
308
|
-
const prerenderedErrorPageFetch = renderOptions?.prerenderedErrorPageFetch ?? fetch;
|
|
309
|
-
if (redirect !== url.pathname) {
|
|
310
|
-
const status = request.method === "GET" ? 301 : 308;
|
|
311
|
-
return new Response(
|
|
312
|
-
redirectTemplate({
|
|
313
|
-
status,
|
|
314
|
-
relativeLocation: url.pathname,
|
|
315
|
-
absoluteLocation: redirect,
|
|
316
|
-
from: request.url
|
|
317
|
-
}),
|
|
318
|
-
{
|
|
319
|
-
status,
|
|
320
|
-
headers: {
|
|
321
|
-
location: redirect + url.search
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
addCookieHeader = renderOptions?.addCookieHeader;
|
|
327
|
-
clientAddress = renderOptions?.clientAddress ?? Reflect.get(request, clientAddressSymbol);
|
|
328
|
-
routeData = renderOptions?.routeData;
|
|
329
|
-
locals = renderOptions?.locals;
|
|
330
|
-
if (routeData) {
|
|
331
|
-
this.#logger.debug(
|
|
332
|
-
"router",
|
|
333
|
-
"The adapter " + this.#manifest.adapterName + " provided a custom RouteData for ",
|
|
334
|
-
request.url
|
|
335
|
-
);
|
|
336
|
-
this.#logger.debug("router", "RouteData:\n" + routeData);
|
|
337
|
-
}
|
|
338
|
-
if (locals) {
|
|
339
|
-
if (typeof locals !== "object") {
|
|
340
|
-
const error = new AstroError(AstroErrorData.LocalsNotAnObject);
|
|
341
|
-
this.#logger.error(null, error.stack);
|
|
342
|
-
return this.#renderError(request, {
|
|
343
|
-
status: 500,
|
|
344
|
-
error,
|
|
345
|
-
clientAddress,
|
|
346
|
-
prerenderedErrorPageFetch
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
if (!routeData) {
|
|
351
|
-
routeData = this.match(request);
|
|
352
|
-
this.#logger.debug("router", "Astro matched the following route for " + request.url);
|
|
353
|
-
this.#logger.debug("router", "RouteData:\n" + routeData);
|
|
354
|
-
}
|
|
355
|
-
if (!routeData) {
|
|
356
|
-
routeData = this.#manifestData.routes.find(
|
|
357
|
-
(route) => route.component === "404.astro" || route.component === DEFAULT_404_COMPONENT
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
if (!routeData) {
|
|
361
|
-
this.#logger.debug("router", "Astro hasn't found routes that match " + request.url);
|
|
362
|
-
this.#logger.debug("router", "Here's the available routes:\n", this.#manifestData);
|
|
363
|
-
return this.#renderError(request, {
|
|
364
|
-
locals,
|
|
365
|
-
status: 404,
|
|
366
|
-
clientAddress,
|
|
367
|
-
prerenderedErrorPageFetch
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
const pathname = this.#getPathnameFromRequest(request);
|
|
371
|
-
const defaultStatus = this.#getDefaultStatusCode(routeData, pathname);
|
|
372
|
-
let response;
|
|
373
|
-
let session;
|
|
374
|
-
try {
|
|
375
|
-
const mod = await this.#pipeline.getModuleForRoute(routeData);
|
|
376
|
-
const renderContext = await RenderContext.create({
|
|
377
|
-
pipeline: this.#pipeline,
|
|
378
|
-
locals,
|
|
379
|
-
pathname,
|
|
380
|
-
request,
|
|
381
|
-
routeData,
|
|
382
|
-
status: defaultStatus,
|
|
383
|
-
clientAddress
|
|
384
|
-
});
|
|
385
|
-
session = renderContext.session;
|
|
386
|
-
response = await renderContext.render(await mod.page());
|
|
387
|
-
} catch (err) {
|
|
388
|
-
this.#logger.error(null, err.stack || err.message || String(err));
|
|
389
|
-
return this.#renderError(request, {
|
|
390
|
-
locals,
|
|
391
|
-
status: 500,
|
|
392
|
-
error: err,
|
|
393
|
-
clientAddress,
|
|
394
|
-
prerenderedErrorPageFetch
|
|
395
|
-
});
|
|
396
|
-
} finally {
|
|
397
|
-
await session?.[PERSIST_SYMBOL]();
|
|
398
|
-
}
|
|
399
|
-
if (REROUTABLE_STATUS_CODES.includes(response.status) && // If the body isn't null, that means the user sets the 404 status
|
|
400
|
-
// but uses the current route to handle the 404
|
|
401
|
-
response.body === null && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
|
|
402
|
-
return this.#renderError(request, {
|
|
403
|
-
locals,
|
|
404
|
-
response,
|
|
405
|
-
status: response.status,
|
|
406
|
-
// We don't have an error to report here. Passing null means we pass nothing intentionally
|
|
407
|
-
// while undefined means there's no error
|
|
408
|
-
error: response.status === 500 ? null : void 0,
|
|
409
|
-
clientAddress,
|
|
410
|
-
prerenderedErrorPageFetch
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
if (response.headers.has(REROUTE_DIRECTIVE_HEADER)) {
|
|
414
|
-
response.headers.delete(REROUTE_DIRECTIVE_HEADER);
|
|
415
|
-
}
|
|
416
|
-
if (addCookieHeader) {
|
|
417
|
-
for (const setCookieHeaderValue of App.getSetCookieFromResponse(response)) {
|
|
418
|
-
response.headers.append("set-cookie", setCookieHeaderValue);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
Reflect.set(response, responseSentSymbol, true);
|
|
422
|
-
return response;
|
|
423
|
-
}
|
|
424
|
-
setCookieHeaders(response) {
|
|
425
|
-
return getSetCookiesFromResponse(response);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Reads all the cookies written by `Astro.cookie.set()` onto the passed response.
|
|
429
|
-
* For example,
|
|
430
|
-
* ```ts
|
|
431
|
-
* for (const cookie_ of App.getSetCookieFromResponse(response)) {
|
|
432
|
-
* const cookie: string = cookie_
|
|
433
|
-
* }
|
|
434
|
-
* ```
|
|
435
|
-
* @param response The response to read cookies from.
|
|
436
|
-
* @returns An iterator that yields key-value pairs as equal-sign-separated strings.
|
|
437
|
-
*/
|
|
438
|
-
static getSetCookieFromResponse = getSetCookiesFromResponse;
|
|
439
|
-
/**
|
|
440
|
-
* If it is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
|
|
441
|
-
* This also handles pre-rendered /404 or /500 routes
|
|
442
|
-
*/
|
|
443
|
-
async #renderError(request, {
|
|
444
|
-
locals,
|
|
445
|
-
status,
|
|
446
|
-
response: originalResponse,
|
|
447
|
-
skipMiddleware = false,
|
|
448
|
-
error,
|
|
449
|
-
clientAddress,
|
|
450
|
-
prerenderedErrorPageFetch
|
|
451
|
-
}) {
|
|
452
|
-
const errorRoutePath = `/${status}${this.#manifest.trailingSlash === "always" ? "/" : ""}`;
|
|
453
|
-
const errorRouteData = matchRoute(errorRoutePath, this.#manifestData);
|
|
454
|
-
const url = new URL(request.url);
|
|
455
|
-
if (errorRouteData) {
|
|
456
|
-
if (errorRouteData.prerender) {
|
|
457
|
-
const maybeDotHtml = errorRouteData.route.endsWith(`/${status}`) ? ".html" : "";
|
|
458
|
-
const statusURL = new URL(
|
|
459
|
-
`${this.#baseWithoutTrailingSlash}/${status}${maybeDotHtml}`,
|
|
460
|
-
url
|
|
461
|
-
);
|
|
462
|
-
if (statusURL.toString() !== request.url) {
|
|
463
|
-
const response2 = await prerenderedErrorPageFetch(statusURL.toString());
|
|
464
|
-
const override = { status, removeContentEncodingHeaders: true };
|
|
465
|
-
return this.#mergeResponses(response2, originalResponse, override);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
const mod = await this.#pipeline.getModuleForRoute(errorRouteData);
|
|
469
|
-
let session;
|
|
470
|
-
try {
|
|
471
|
-
const renderContext = await RenderContext.create({
|
|
472
|
-
locals,
|
|
473
|
-
pipeline: this.#pipeline,
|
|
474
|
-
middleware: skipMiddleware ? NOOP_MIDDLEWARE_FN : void 0,
|
|
475
|
-
pathname: this.#getPathnameFromRequest(request),
|
|
476
|
-
request,
|
|
477
|
-
routeData: errorRouteData,
|
|
478
|
-
status,
|
|
479
|
-
props: { error },
|
|
480
|
-
clientAddress
|
|
481
|
-
});
|
|
482
|
-
session = renderContext.session;
|
|
483
|
-
const response2 = await renderContext.render(await mod.page());
|
|
484
|
-
return this.#mergeResponses(response2, originalResponse);
|
|
485
|
-
} catch {
|
|
486
|
-
if (skipMiddleware === false) {
|
|
487
|
-
return this.#renderError(request, {
|
|
488
|
-
locals,
|
|
489
|
-
status,
|
|
490
|
-
response: originalResponse,
|
|
491
|
-
skipMiddleware: true,
|
|
492
|
-
clientAddress,
|
|
493
|
-
prerenderedErrorPageFetch
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
} finally {
|
|
497
|
-
await session?.[PERSIST_SYMBOL]();
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
const response = this.#mergeResponses(new Response(null, { status }), originalResponse);
|
|
501
|
-
Reflect.set(response, responseSentSymbol, true);
|
|
502
|
-
return response;
|
|
503
|
-
}
|
|
504
|
-
#mergeResponses(newResponse, originalResponse, override) {
|
|
505
|
-
let newResponseHeaders = newResponse.headers;
|
|
506
|
-
if (override?.removeContentEncodingHeaders) {
|
|
507
|
-
newResponseHeaders = new Headers(newResponseHeaders);
|
|
508
|
-
newResponseHeaders.delete("Content-Encoding");
|
|
509
|
-
newResponseHeaders.delete("Content-Length");
|
|
510
|
-
}
|
|
511
|
-
if (!originalResponse) {
|
|
512
|
-
if (override !== void 0) {
|
|
513
|
-
return new Response(newResponse.body, {
|
|
514
|
-
status: override.status,
|
|
515
|
-
statusText: newResponse.statusText,
|
|
516
|
-
headers: newResponseHeaders
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
return newResponse;
|
|
520
|
-
}
|
|
521
|
-
const status = override?.status ? override.status : originalResponse.status === 200 ? newResponse.status : originalResponse.status;
|
|
522
|
-
try {
|
|
523
|
-
originalResponse.headers.delete("Content-type");
|
|
524
|
-
} catch {
|
|
525
|
-
}
|
|
526
|
-
const mergedHeaders = new Map([
|
|
527
|
-
...Array.from(newResponseHeaders),
|
|
528
|
-
...Array.from(originalResponse.headers)
|
|
529
|
-
]);
|
|
530
|
-
const newHeaders = new Headers();
|
|
531
|
-
for (const [name, value] of mergedHeaders) {
|
|
532
|
-
newHeaders.set(name, value);
|
|
533
|
-
}
|
|
534
|
-
return new Response(newResponse.body, {
|
|
535
|
-
status,
|
|
536
|
-
statusText: status === 200 ? newResponse.statusText : originalResponse.statusText,
|
|
537
|
-
// If you're looking at here for possible bugs, it means that it's not a bug.
|
|
538
|
-
// With the middleware, users can meddle with headers, and we should pass to the 404/500.
|
|
539
|
-
// If users see something weird, it's because they are setting some headers they should not.
|
|
540
|
-
//
|
|
541
|
-
// Although, we don't want it to replace the content-type, because the error page must return `text/html`
|
|
542
|
-
headers: newHeaders
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
#getDefaultStatusCode(routeData, pathname) {
|
|
546
|
-
if (!routeData.pattern.test(pathname)) {
|
|
547
|
-
for (const fallbackRoute of routeData.fallbackRoutes) {
|
|
548
|
-
if (fallbackRoute.pattern.test(pathname)) {
|
|
549
|
-
return 302;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
const route = removeTrailingForwardSlash(routeData.route);
|
|
554
|
-
if (route.endsWith("/404")) return 404;
|
|
555
|
-
if (route.endsWith("/500")) return 500;
|
|
556
|
-
return 200;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
13
|
export {
|
|
560
14
|
App,
|
|
561
|
-
|
|
15
|
+
AppPipeline,
|
|
16
|
+
BaseApp,
|
|
17
|
+
createConsoleLogger,
|
|
18
|
+
deserializeManifest,
|
|
19
|
+
deserializeRouteData,
|
|
20
|
+
deserializeRouteInfo,
|
|
21
|
+
fromRoutingStrategy,
|
|
22
|
+
serializeRouteData,
|
|
23
|
+
serializeRouteInfo,
|
|
24
|
+
toRoutingStrategy
|
|
562
25
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { consoleLogDestination } from "../logger/console.js";
|
|
2
|
+
import { Logger } from "../logger/core.js";
|
|
3
|
+
function createConsoleLogger(level) {
|
|
4
|
+
return new Logger({
|
|
5
|
+
dest: consoleLogDestination,
|
|
6
|
+
level: level ?? "info"
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
createConsoleLogger
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SerializedRouteData } from '../../types/astro.js';
|
|
2
|
+
import type { AstroConfig, RouteData } from '../../types/public/index.js';
|
|
3
|
+
import type { RoutesList } from '../../types/astro.js';
|
|
4
|
+
import type { RouteInfo, SerializedSSRManifest, SSRManifest, SerializedRouteInfo } from './types.js';
|
|
5
|
+
export declare function deserializeManifest(serializedManifest: SerializedSSRManifest, routesList?: RoutesList): SSRManifest;
|
|
6
|
+
export declare function serializeRouteData(routeData: RouteData, trailingSlash: AstroConfig['trailingSlash']): SerializedRouteData;
|
|
7
|
+
export declare function deserializeRouteData(rawRouteData: SerializedRouteData): RouteData;
|
|
8
|
+
export declare function serializeRouteInfo(routeInfo: RouteInfo, trailingSlash: AstroConfig['trailingSlash']): SerializedRouteInfo;
|
|
9
|
+
export declare function deserializeRouteInfo(rawRouteInfo: SerializedRouteInfo): RouteInfo;
|