Skip to content

Commit fc21af7

Browse files
Corvincevhess
andauthored
feat(dev): support HTTP2 even if proxy feature is used (#20869)
Co-authored-by: vhess <hess@sec-bremen.de>
1 parent d636220 commit fc21af7

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

docs/config/server-options.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ Set to `true` to exit if port is already in use, instead of automatically trying
9292

9393
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()`.
9494

95-
Note that this downgrades to TLS only when the [`server.proxy` option](#server-proxy) is also used.
96-
9795
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.
9896

9997
## server.open

packages/vite/src/node/http.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ export interface CorsOptions {
115115
export type CorsOrigin = boolean | string | RegExp | (string | RegExp)[]
116116

117117
export async function resolveHttpServer(
118-
{ proxy }: CommonServerOptions,
119118
app: Connect.Server,
120119
httpsOptions?: HttpsServerOptions,
121120
): Promise<HttpServer> {
@@ -124,24 +123,18 @@ export async function resolveHttpServer(
124123
return createServer(app)
125124
}
126125

127-
// #484 fallback to http1 when proxy is needed.
128-
if (proxy) {
129-
const { createServer } = await import('node:https')
130-
return createServer(httpsOptions, app)
131-
} else {
132-
const { createSecureServer } = await import('node:http2')
133-
return createSecureServer(
134-
{
135-
// Manually increase the session memory to prevent 502 ENHANCE_YOUR_CALM
136-
// errors on large numbers of requests
137-
maxSessionMemory: 1000,
138-
...httpsOptions,
139-
allowHTTP1: true,
140-
},
141-
// @ts-expect-error TODO: is this correct?
142-
app,
143-
)
144-
}
126+
const { createSecureServer } = await import('node:http2')
127+
return createSecureServer(
128+
{
129+
// Manually increase the session memory to prevent 502 ENHANCE_YOUR_CALM
130+
// errors on large numbers of requests
131+
maxSessionMemory: 1000,
132+
...httpsOptions,
133+
allowHTTP1: true,
134+
},
135+
// @ts-expect-error TODO: is this correct?
136+
app,
137+
)
145138
}
146139

147140
export async function resolveHttpsConfig(

packages/vite/src/node/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export async function preview(
146146

147147
const httpsOptions = await resolveHttpsConfig(config.preview.https)
148148
const app = connect() as Connect.Server
149-
const httpServer = await resolveHttpServer(config.preview, app, httpsOptions)
149+
const httpServer = await resolveHttpServer(app, httpsOptions)
150150
setClientErrorHandler(httpServer, config.logger)
151151

152152
const options = config.preview

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ export async function _createServer(
478478
const middlewares = connect() as Connect.Server
479479
const httpServer = middlewareMode
480480
? null
481-
: await resolveHttpServer(serverConfig, middlewares, httpsOptions)
481+
: await resolveHttpServer(middlewares, httpsOptions)
482482

483483
const ws = createWebSocketServer(httpServer, config, httpsOptions)
484484

0 commit comments

Comments
 (0)