Prevent static assets from being caught by catch-all routes#16047
Prevent static assets from being caught by catch-all routes#16047
Conversation
🦋 Changeset detectedLatest commit: cc3efea The changes in this PR will be included in the next version bump. 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 |
delucis
left a comment
There was a problem hiding this comment.
Noting that our docs say
Note that middleware mode does not do file serving. You’ll need to configure your HTTP framework to do that for you. By default the client assets are written to
./dist/client/.
I guess these assets are unrelated to that?
|
@delucis The description wasn't great so I updated it. Middleware mode doesn't serve static assets. The bug was that static assets were being caught by catch-all routes astro/packages/astro/src/core/app/base.ts Line 244 in 1768ad5 So this was preventing the request from hitting the next middleware (see the test, it's the fastify static middleware) |
| 'astro': patch | ||
| --- | ||
|
|
||
| Fixes CSS, fonts, and other assets failing to load when using `@astrojs/node` in middleware mode with a catch-all route. Previously these assets were incorrectly matched by the catch-all instead of being served as static files. |
There was a problem hiding this comment.
Thanks for the clarification! Maybe we can tweak the changeset to describe that and not suggest that those assets will definitely load (if a user doesn’t add their own static file middleware)?
| Fixes CSS, fonts, and other assets failing to load when using `@astrojs/node` in middleware mode with a catch-all route. Previously these assets were incorrectly matched by the catch-all instead of being served as static files. | |
| Fixes catch-all routes incorrectly intercepting requests for static assets when using the `@astrojs/node` adapter in middleware mode. |
Otherwise all looks good to me!
Changes
ssrAssetsPerEnvironmentis a recently added property that's used to know what to copy over to the client folderTesting
packages/integrations/node/test/fixtures/ssr-assets-middleware/with anindex.astrothat imports a CSS file and a[...path].astrocatch-all page — the minimal setup required to reproduce the bug.node-middleware.test.js(middleware with fastify and catch-all route: SSR assets in manifest) that builds withassetsInlineLimit: 0, starts a Fastify server, and asserts that requesting the CSS asset URL returnstext/cssrather thantext/htmlfrom the catch-all. The test fails on unfixed code and passes with the fix.Docs
No docs update needed — this is a bug fix restoring documented behavior with no API changes.
Fixes #16039