Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(vite): don't match other endpoints _beginning_ with _nuxt #10121

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
fix(vite): don't match other endpoints _beginning_ with _nuxt
danielroe committed Jan 16, 2023
commit 1494adee919acdf7de1dee89a8e06cea358acce3
5 changes: 3 additions & 2 deletions packages/vite/src/client.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
import type { ServerOptions } from 'vite'
import { logger } from '@nuxt/kit'
import { getPort } from 'get-port-please'
import { joinURL, withoutLeadingSlash, withoutTrailingSlash } from 'ufo'
import { joinURL, withoutLeadingSlash, withTrailingSlash, withoutTrailingSlash } from 'ufo'
import defu from 'defu'
import type { OutputOptions } from 'rollup'
import { defineEventHandler } from 'h3'
@@ -130,11 +130,12 @@ export async function buildClient (ctx: ViteBuildContext) {
next()
}
})
const base = withTrailingSlash(clientConfig.base)
const viteMiddleware = defineEventHandler(async (event) => {
// Workaround: vite devmiddleware modifies req.url
const originalURL = event.node.req.url!
// @ts-expect-error _skip_transform is a private property
event.node.req._skip_transform = !originalURL.startsWith(clientConfig.base!)
event.node.req._skip_transform = !originalURL.startsWith(base)
await new Promise((resolve, reject) => {
viteServer.middlewares.handle(event.node.req, event.node.res, (err: Error) => {
event.node.req.url = originalURL