Skip to content

Commit c35e100

Browse files
authored
fix: configure proxy before subscribing to error events (#12263)
1 parent 520d84e commit c35e100

File tree

1 file changed

+4
-4
lines changed
  • packages/vite/src/node/server/middlewares

1 file changed

+4
-4
lines changed

packages/vite/src/node/server/middlewares/proxy.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export function proxyMiddleware(
4747
}
4848
const proxy = httpProxy.createProxyServer(opts) as HttpProxy.Server
4949

50+
if (opts.configure) {
51+
opts.configure(proxy, opts)
52+
}
53+
5054
proxy.on('error', (err, req, originalRes) => {
5155
// When it is ws proxy, res is net.Socket
5256
const res = originalRes as http.ServerResponse | net.Socket
@@ -75,10 +79,6 @@ export function proxyMiddleware(
7579
res.end()
7680
}
7781
})
78-
79-
if (opts.configure) {
80-
opts.configure(proxy, opts)
81-
}
8282
// clone before saving because http-proxy mutates the options
8383
proxies[context] = [proxy, { ...opts }]
8484
})

0 commit comments

Comments
 (0)