Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve _routes.json generation #423

Conversation

schummar
Copy link
Contributor

@schummar schummar commented Oct 14, 2024

Changes

This is a result of the discussion in #374. I found a quick win that makes things a lot better without additional risk. More could be done to generate smaller, correct solutions for even more cases - but as a first step I'm pretty happy with this.

Problem: When there are a lot of static pages (resulting in more than 100 combined include/exclude entries, the adapter would generate a _routes.json with a /* include and a truncated array of excludes. Even if having a few includes and no excludes instead would be a correct solution too - with the added benefit of no unnecessary function invocations.

Solution: I improved the condition which switches between the two options (option 1 = /* include + many excludes; option 2 = many includes, fewer excludes). Now option 2 is chosen if: there is a static 404 AND option 2 is below the limit.

Testing

I added two test cases with many static files. One with and one without a static 404 file.

Docs

Not sure if anything needs to be documented.

Copy link

changeset-bot bot commented Oct 14, 2024

🦋 Changeset detected

Latest commit: e843967

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@astrojs/cloudflare Minor
@test/astro-cloudflare-astro-dev-platform Patch
@test/astro-cloudflare-astro-env Patch
@test/astro-cloudflare-compile-image-service Patch
@test/astro-cloudflare-external-image-service Patch
@test/astro-cloudflare-wasm Patch
@test/astro-cloudflare-no-output Patch
@test/astro-cloudflare-routes-json Patch
@test/astro-cloudflare-with-solid-js Patch
@test/astro-cloudflare-wrangler-preview-platform Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@alexanderniebuhr alexanderniebuhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to make sense to me.

@alexanderniebuhr alexanderniebuhr changed the title feat: better _routes.json for many static files feat: improve _routes.json generation Oct 21, 2024
@alexanderniebuhr alexanderniebuhr merged commit 169ac24 into withastro:main Oct 21, 2024
8 checks passed
@github-actions github-actions bot mentioned this pull request Oct 21, 2024
@schummar schummar deleted the feature/better-routes-json-for-many-static-files branch October 21, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants