From 98a1025254722ebd972fc092b458ffea59c71d3d Mon Sep 17 00:00:00 2001 From: Corvince <13568919+Corvince@users.noreply.github.com> Date: Wed, 1 Oct 2025 20:28:07 +0200 Subject: [PATCH 1/3] fix #4184 - http-proxy3 supports https server With the switch to http-proxy3 it should no longer be neccessary to fall back to http when using https and proxy at the same time --- packages/vite/src/node/http.ts | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index 3d0a09d0b5a18c..5b78fd11795859 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -124,24 +124,18 @@ export async function resolveHttpServer( return createServer(app) } - // #484 fallback to http1 when proxy is needed. - if (proxy) { - const { createServer } = await import('node:https') - return createServer(httpsOptions, app) - } else { - const { createSecureServer } = await import('node:http2') - return createSecureServer( - { - // Manually increase the session memory to prevent 502 ENHANCE_YOUR_CALM - // errors on large numbers of requests - maxSessionMemory: 1000, - ...httpsOptions, - allowHTTP1: true, - }, - // @ts-expect-error TODO: is this correct? - app, - ) - } + const { createSecureServer } = await import('node:http2') + return createSecureServer( + { + // Manually increase the session memory to prevent 502 ENHANCE_YOUR_CALM + // errors on large numbers of requests + maxSessionMemory: 1000, + ...httpsOptions, + allowHTTP1: true, + }, + // @ts-expect-error TODO: is this correct? + app, + ) } export async function resolveHttpsConfig( From 3b28facc0fe771e01c031f85bf8cad660029ebd1 Mon Sep 17 00:00:00 2001 From: Corvince <13568919+Corvince@users.noreply.github.com> Date: Wed, 1 Oct 2025 20:33:53 +0200 Subject: [PATCH 2/3] Update TLS and HTTP/2 options documentation Clarified the note regarding TLS downgrade and certificate requirements. --- docs/config/server-options.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/config/server-options.md b/docs/config/server-options.md index 6e646c97472e92..1e9fa6e3df872f 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -92,8 +92,6 @@ Set to `true` to exit if port is already in use, instead of automatically trying Enable TLS + HTTP/2. The value is an [options object](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) passed to `https.createServer()`. -Note that this downgrades to TLS only when the [`server.proxy` option](#server-proxy) is also used. - A valid certificate is needed. For a basic setup, you can add [@vitejs/plugin-basic-ssl](https://github.com/vitejs/vite-plugin-basic-ssl) to the project plugins, which will automatically create and cache a self-signed certificate. But we recommend creating your own certificates. ## server.open From 48da57b4a19f43b33dbdfd114e8d13c6f8d7432d Mon Sep 17 00:00:00 2001 From: vhess Date: Tue, 14 Oct 2025 15:01:30 +0200 Subject: [PATCH 3/3] remove now unused parameter from resolveHttpServer --- packages/vite/src/node/http.ts | 1 - packages/vite/src/node/preview.ts | 2 +- packages/vite/src/node/server/index.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index 5b78fd11795859..fa5f6cf6531e0d 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -115,7 +115,6 @@ export interface CorsOptions { export type CorsOrigin = boolean | string | RegExp | (string | RegExp)[] export async function resolveHttpServer( - { proxy }: CommonServerOptions, app: Connect.Server, httpsOptions?: HttpsServerOptions, ): Promise { diff --git a/packages/vite/src/node/preview.ts b/packages/vite/src/node/preview.ts index c45e8e2256ada1..67beb929ff670d 100644 --- a/packages/vite/src/node/preview.ts +++ b/packages/vite/src/node/preview.ts @@ -146,7 +146,7 @@ export async function preview( const httpsOptions = await resolveHttpsConfig(config.preview.https) const app = connect() as Connect.Server - const httpServer = await resolveHttpServer(config.preview, app, httpsOptions) + const httpServer = await resolveHttpServer(app, httpsOptions) setClientErrorHandler(httpServer, config.logger) const options = config.preview diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 7d250a68a8ff41..c13e7effb05564 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -478,7 +478,7 @@ export async function _createServer( const middlewares = connect() as Connect.Server const httpServer = middlewareMode ? null - : await resolveHttpServer(serverConfig, middlewares, httpsOptions) + : await resolveHttpServer(middlewares, httpsOptions) const ws = createWebSocketServer(httpServer, config, httpsOptions)