Skip to content

Commit

Permalink
fix: use correct proxy config in preview (#7604)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Apr 4, 2022
1 parent b620587 commit cf59005
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/vite/src/node/preview.ts
Expand Up @@ -78,8 +78,9 @@ export async function preview(
}

// proxy
if (config.preview.proxy) {
app.use(proxyMiddleware(httpServer, config))
const { proxy } = config.preview
if (proxy) {
app.use(proxyMiddleware(httpServer, proxy, config))
}

app.use(compression())
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/index.ts
Expand Up @@ -516,7 +516,7 @@ export async function createServer(
// proxy
const { proxy } = serverConfig
if (proxy) {
middlewares.use(proxyMiddleware(httpServer, config))
middlewares.use(proxyMiddleware(httpServer, proxy, config))
}

// base
Expand Down
5 changes: 2 additions & 3 deletions packages/vite/src/node/server/middlewares/proxy.ts
Expand Up @@ -5,7 +5,7 @@ import { HMR_HEADER } from '../ws'
import type { Connect } from 'types/connect'
import type { HttpProxy } from 'types/http-proxy'
import colors from 'picocolors'
import type { ResolvedConfig } from '../..'
import type { CommonServerOptions, ResolvedConfig } from '../..'

const debug = createDebugger('vite:proxy')

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

export function proxyMiddleware(
httpServer: http.Server | null,
options: NonNullable<CommonServerOptions['proxy']>,
config: ResolvedConfig
): Connect.NextHandleFunction {
const options = config.server.proxy!

// lazy require only when proxy is used
const proxies: Record<string, [HttpProxy.Server, ProxyOptions]> = {}

Expand Down

0 comments on commit cf59005

Please sign in to comment.