withastro / adapters

Home for Astro's core maintained adapters
47 stars 26 forks source link

When `build.format: "file"`, `_routes.json` is not configured correctly and SSR is preferred over SSG. #193

Closed totto2727 closed 3 months ago

totto2727 commented 3 months ago

Astro Info

Astro                    v4.4.15
Node                     v20.11.1
System                   macOS (arm64)
Package Manager          pnpm
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/svelte

Describe the Bug

The output of Cloudflare Adaptor,dist/_routes.json, has a different configuration depending on the value of build.format in astro.config.mjs.

In particular, the exclude in build.format: "file" does not seem to be set correctly.

In build.format: "directory", /pages/ssg/index.astro takes precedence over /pages/ssg/[ssr]/index.astro.

However, with build.format: "file", /pages/ssg/[ssr]/index.astro takes precedence and a 404 is returned when trying to access /pages/ssg/index.astro.

This is because exclude does not include "/ssg/" and SSR with "/ssg/*" in include are preferred.

This is not surprising, since the SSR script does not have a corresponding process for /pages/ssg/index.astro, but the difference in behavior is annoying.

What's the expected result?

This is also true for mode: "hybrid".

dist/_route.json outputs

mode: "server", build.format: "file"

expected

{
  "version": 1,
  "include": [
    "/ssg/*",
    "/_image"
  ],
  "exclude": [
    "/ssg/",
    "/ssg.html"
  ]
}

actual

{
  "version": 1,
  "include": [
    "/ssg/*",
    "/_image"
  ],
  "exclude": []
}

mode: "server", build.format: "file"

No problem.

{
  "version": 1,
  "include": [
    "/ssg/*",
    "/_image"
  ],
  "exclude": [
    "/ssg/",
    "/ssg/index.html"
  ]
}

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-3jxjgu?file=dist%2F_routes.json

Participation