Skip to content

Prevent static assets from being caught by catch-all routes#16047

Merged
matthewp merged 4 commits intomainfrom
node-middleware-missing-assets
Mar 27, 2026
Merged

Prevent static assets from being caught by catch-all routes#16047
matthewp merged 4 commits intomainfrom
node-middleware-missing-assets

Conversation

@matthewp
Copy link
Copy Markdown
Contributor

@matthewp matthewp commented Mar 23, 2026

Changes

  • ssrAssetsPerEnvironment is a recently added property that's used to know what to copy over to the client folder
  • This iterates over them and adds them to the manifest so the Node adapter knows to serve them.

Testing

  • Added a new fixture packages/integrations/node/test/fixtures/ssr-assets-middleware/ with an index.astro that imports a CSS file and a [...path].astro catch-all page — the minimal setup required to reproduce the bug.
  • Added a regression test in node-middleware.test.js (middleware with fastify and catch-all route: SSR assets in manifest) that builds with assetsInlineLimit: 0, starts a Fastify server, and asserts that requesting the CSS asset URL returns text/css rather than text/html from 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

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 23, 2026

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) labels Mar 23, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 23, 2026

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing node-middleware-missing-assets (cc3efea) with main (47694d0)

Open in CodSpeed

@matthewp matthewp marked this pull request as ready for review March 24, 2026 13:06
Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

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?

@matthewp matthewp changed the title Node adapter middleware mode: serve SSR-emitted assets instead of matching catch-all routes Prevent static assets from being caught by catch-all routes Mar 27, 2026
@matthewp
Copy link
Copy Markdown
Contributor Author

@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 [...path].astro because we didn't have them in manifest.assets. Here is where we return undefined if a request is for static assets:

if (this.manifest.assets.has(url.pathname)) return undefined;

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)?

Suggested change
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!

@matthewp matthewp merged commit 711f837 into main Mar 27, 2026
44 of 45 checks passed
@matthewp matthewp deleted the node-middleware-missing-assets branch March 27, 2026 18:32
@astrobot-houston astrobot-houston mentioned this pull request Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Built assets are not served by the Node adapter in middleware mode

2 participants