Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct proxy config in preview #7604

Merged
merged 1 commit into from Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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