[PR #602] [MERGED] fix: serve public directory files after middleware in production #703

Closed
opened 2026-05-06 13:09:39 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/602
Author: @southpolesteve
Created: 3/20/2026
Status: Merged
Merged: 3/20/2026
Merged by: @james-elicx

Base: mainHead: fix/serve-static-after-middleware


📝 Commits (2)

  • 83e1aa6 fix: serve public directory files after middleware in production
  • 1ad9652 apply config headers before serving public directory static files

📊 Changes

1 file changed (+32 additions, -9 deletions)

View changed files

📝 packages/vinext/src/server/prod-server.ts (+32 -9)

📄 Description

Summary

  • Split static file serving into two phases in the production server
  • Hashed build assets (/assets/*) are still served before middleware (step 1), since they are always public
  • Public directory files (everything else) are now served after middleware (step 5b), so middleware can intercept or redirect them

Details

Previously, all static files from dist/client/ were served in step 1, before middleware had a chance to run. This meant middleware could not protect or redirect requests to files from the public/ directory.

Next.js serves _next/static/* (build output) directly but runs middleware before serving public/ directory files. This change brings vinext in line with that behavior by only pre-serving Vite's hashed build output (/assets/*) and deferring everything else until after middleware.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/602 **Author:** [@southpolesteve](https://github.com/southpolesteve) **Created:** 3/20/2026 **Status:** ✅ Merged **Merged:** 3/20/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/serve-static-after-middleware` --- ### 📝 Commits (2) - [`83e1aa6`](https://github.com/cloudflare/vinext/commit/83e1aa6fd2cb12579c8161481af8e910d328a7a4) fix: serve public directory files after middleware in production - [`1ad9652`](https://github.com/cloudflare/vinext/commit/1ad96524f1eca00ca2df050472a0dcd196d0f12a) apply config headers before serving public directory static files ### 📊 Changes **1 file changed** (+32 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/server/prod-server.ts` (+32 -9) </details> ### 📄 Description ## Summary - Split static file serving into two phases in the production server - Hashed build assets (`/assets/*`) are still served before middleware (step 1), since they are always public - Public directory files (everything else) are now served after middleware (step 5b), so middleware can intercept or redirect them ## Details Previously, all static files from `dist/client/` were served in step 1, before middleware had a chance to run. This meant middleware could not protect or redirect requests to files from the `public/` directory. Next.js serves `_next/static/*` (build output) directly but runs middleware before serving `public/` directory files. This change brings vinext in line with that behavior by only pre-serving Vite's hashed build output (`/assets/*`) and deferring everything else until after middleware. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:39 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#703
No description provided.