Skip to content

Commit cf59005

Browse files
authored
fix: use correct proxy config in preview (#7604)
1 parent b620587 commit cf59005

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

packages/vite/src/node/preview.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ export async function preview(
7878
}
7979

8080
// proxy
81-
if (config.preview.proxy) {
82-
app.use(proxyMiddleware(httpServer, config))
81+
const { proxy } = config.preview
82+
if (proxy) {
83+
app.use(proxyMiddleware(httpServer, proxy, config))
8384
}
8485

8586
app.use(compression())

packages/vite/src/node/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export async function createServer(
516516
// proxy
517517
const { proxy } = serverConfig
518518
if (proxy) {
519-
middlewares.use(proxyMiddleware(httpServer, config))
519+
middlewares.use(proxyMiddleware(httpServer, proxy, config))
520520
}
521521

522522
// base

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { HMR_HEADER } from '../ws'
55
import type { Connect } from 'types/connect'
66
import type { HttpProxy } from 'types/http-proxy'
77
import colors from 'picocolors'
8-
import type { ResolvedConfig } from '../..'
8+
import type { CommonServerOptions, ResolvedConfig } from '../..'
99

1010
const debug = createDebugger('vite:proxy')
1111

@@ -30,10 +30,9 @@ export interface ProxyOptions extends HttpProxy.ServerOptions {
3030

3131
export function proxyMiddleware(
3232
httpServer: http.Server | null,
33+
options: NonNullable<CommonServerOptions['proxy']>,
3334
config: ResolvedConfig
3435
): Connect.NextHandleFunction {
35-
const options = config.server.proxy!
36-
3736
// lazy require only when proxy is used
3837
const proxies: Record<string, [HttpProxy.Server, ProxyOptions]> = {}
3938

0 commit comments

Comments
 (0)