From b719f1bb210af179eb4a47035d01992e5d0e5202 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 2 Nov 2022 17:05:17 +0800 Subject: [PATCH] fix(vite): handle all vite middleware routes (#8601) --- packages/vite/src/client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index f6fde87886..6c2bf0c04d 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -109,10 +109,11 @@ export async function buildClient (ctx: ViteBuildContext) { const viteServer = await vite.createServer(clientConfig) ctx.clientServer = viteServer await ctx.nuxt.callHook('vite:serverCreated', viteServer, { isClient: true, isServer: false }) + const viteRoutes = viteServer.middlewares.stack.map(m => m.route).filter(r => r.length > 1) const viteMiddleware = defineEventHandler(async (event) => { // Workaround: vite devmiddleware modifies req.url const originalURL = event.req.url! - if (!originalURL.startsWith('/__nuxt_vite_node__') && !originalURL.startsWith(clientConfig.base!)) { + if (!viteRoutes.some(route => originalURL.startsWith(route)) && !originalURL.startsWith(clientConfig.base!)) { event.req.url = joinURL('/__url', originalURL) } await new Promise((resolve, reject) => {