nitro icon indicating copy to clipboard operation
nitro copied to clipboard

feat: use wildcard excludes in Cloudflare Pages preset

Open Brendonovich opened this issue 1 year ago โ€ข 1 comments

๐Ÿ”— Linked issue

#2068

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • [ ] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [x] ๐Ÿ‘Œ Enhancement (improving an existing functionality like performance)
  • [ ] โœจ New feature (a non-breaking change that adds functionality)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

Cloudflare Pages has a 100 entry limit across routes.include and routes.exclude. The way that routes.exclude is currently generated makes that limit get hit pretty quickly, since each file to be excluded is listed individually. Thankfully, CF supports using wildcards to exclude whole folders and way more than 100 files. This PR adds the generateExcludes function, which attempts to combine as many of the excluded files into wildcard paths as possible, taking into account directories that contain files that have been marked specifically as non-excludable.

This setup has been working for us at Mattrax for a while, but generateExcludes probably needs more testing and possibly some unit tests.

Resolves #2068

Also made some smaller changes:

  • The declaration of routes uses satisfies rather than a hardcoded type as it allows some non-null assertions to be removed
  • _headers generation ignores values set for the same headers for previous sets of routes, since I don't get the impression that headers from routeRules are intended to be additive. We rely on this as we have cache settings at /* that we override for certain routes (and would like nitro to override).

๐Ÿ“ Checklist

  • [x] I have linked an issue or discussion.
  • [x] I have updated the documentation accordingly.

Brendonovich avatar May 24 '24 09:05 Brendonovich

Thanks for PR dear @Brendonovich and sorry for late reply.

I think in order to move it forward, it would be better if we add couple of unit tests and if possible, break it down to smaller changes ๐Ÿ™๐Ÿผ

pi0 avatar Sep 24 '24 19:09 pi0