Skip to content

Commit

Permalink
fix: configure proxy before subscribing to error events (#12263)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeorin committed Mar 2, 2023
1 parent 520d84e commit c35e100
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vite/src/node/server/middlewares/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export function proxyMiddleware(
}
const proxy = httpProxy.createProxyServer(opts) as HttpProxy.Server

if (opts.configure) {
opts.configure(proxy, opts)
}

proxy.on('error', (err, req, originalRes) => {
// When it is ws proxy, res is net.Socket
const res = originalRes as http.ServerResponse | net.Socket
Expand Down Expand Up @@ -75,10 +79,6 @@ export function proxyMiddleware(
res.end()
}
})

if (opts.configure) {
opts.configure(proxy, opts)
}
// clone before saving because http-proxy mutates the options
proxies[context] = [proxy, { ...opts }]
})
Expand Down

0 comments on commit c35e100

Please sign in to comment.