Skip to content
Closed
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
14 changes: 14 additions & 0 deletions packages/vite/src/node/server/middlewares/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,20 @@ export function proxyMiddleware(
debug?.(`${req.url} -> ${opts.target || opts.forward}`)
if (opts.rewrite) {
req.url = opts.rewrite(req.url!)
// some users set `''` to req.url
// this was supported by http-proxy, but is not supported by http-proxy-3
const target = opts.target
if (
(req.url === '' || req.url.startsWith('?')) &&
target &&
opts.prependPath !== false
) {
const normalizedTarget =
typeof target === 'string' ? new URL(target) : target
req.url =
'pathname' in normalizedTarget ? normalizedTarget.pathname : '/'
options.prependPath = false
}
}
proxy.web(req, res, options)
return
Expand Down
Loading