Skip to content

Cloudflare adapter incorrectly includes _headers and _redirects as static requests #9041

@teemingc

Description

@teemingc

Describe the bug

It's possible to write custom headers and redirects for static requests by including a _headers or _redirects file in a SvelteKit project's /static/ directory.

However, this gets incorrectly included as a retrievable static asset in the _routes.json file and causes:

  • requests the path to not render a 404.
  • uses up an include rule which is limited to 100 rules.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-hv4zek?file=package.json,.svelte-kit%2Fcloudflare%2F_routes.json&terminal=dev

Run npm run build and check the output of .svelte-kit/cloudflare/_routes.json. It incorrectly includes the _headers and _redirects files as static requests in _routes.json

Live example

https://brgh.church/_headers

Expected

Navigating to the non-existent URL should trigger the Cloudflare worker and render the 404 page.

Actual

The URL bypasses the Cloudflare worker and returns the root prerendered index.html page.

Logs

No response

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions