withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.98k stars 2.5k forks source link

fix(routing): middleware in dev #12420

Closed ematipico closed 1 week ago

ematipico commented 1 week ago

Changes

Closes https://github.com/withastro/astro/issues/12391 Closes PLT-2627

The middleware is called even when a user doesn't have a route that doesn't match an existing FS route. Users can return a Response that isn't a 404.

The dev server didn't know that, so this PR fixes it.

To understand this use case, I decoded to add a tiny logic to our no-op middleware, which is used only when the user doesn't have a middleware. The no-op middleware adds an arbitrary header. If header isn't present, it means that the user have their own middleware, so we need to return any status returned by the .render function.

Testing

Added two new test cases

Docs

N/A

changeset-bot[bot] commented 1 week ago

🦋 Changeset detected

Latest commit: 1fd52385c225daf8c9465aa9eab3d1d09c1cfd2e

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

codspeed-hq[bot] commented 1 week ago

CodSpeed Performance Report

Merging #12420 will not alter performance

Comparing fix/middleware-dev (1fd5238) with main (e723e9e)

Summary

✅ 1 untouched benchmarks