Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/build/vite/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,18 @@ export async function configureViteDevServer(
}
};

// Handle as first middleware for direct requests
// Handle server routes first to avoid conflicts with static assets served by Vite from the root
// https://github.com/vitejs/vite/pull/20866
server.middlewares.use(function nitroDevMiddlewarePre(req, res, next) {
const fetchDest = req.headers["sec-fetch-dest"];
if (fetchDest) {
res.setHeader("vary", "sec-fetch-dest");
}
const ext = (req.url || "").match(/\.([a-z0-9]+)(?:[?#]|$)/i)?.[1] || "";
res.setHeader("vary", "sec-fetch-dest");
if (
!ext &&
(!fetchDest || /^(document|iframe|frame|empty)$/.test(fetchDest))
// Originating from browser tab or no fetch dest (curl, fetch, etc) and (not script, style, image, etc)
(!fetchDest || /^(document|iframe|frame|empty)$/.test(fetchDest)) &&
// No file extension (not /src/index.ts)
!req.url!.match(/\.([a-z0-9]+)(?:[?#]|$)/i)?.[1] &&
// Special prefixes (/__vue-router/auto-routes, /@vite-plugin-layouts/, etc)
!/^\/(?:__|@)/.test(req.url!)
) {
nitroDevMiddleware(req, res, next);
} else {
Expand Down
Loading