Skip to content

Commit c80b1d8

Browse files
authored
fix: set no-op proxy config to get Vite HTTPS working (#12907)
1 parent 951224d commit c80b1d8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

.changeset/unlucky-walls-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: when using `@vitejs/plugin-basic-ssl`, set a no-op proxy config to downgrade from HTTP/2 to TLS since `undici` does not yet enable HTTP/2 by default

packages/kit/src/exports/vite/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,22 @@ async function kit({ svelte_config }) {
349349
* Stores the final config.
350350
*/
351351
configResolved(config) {
352+
// we search for this plugin by name because we can't detect it
353+
// since it doesn't directly modify the https config unlike the mkcert plugin
354+
const vite_basic_ssl = config.plugins.find(({ name }) => name === 'vite:basic-ssl');
355+
356+
// by default, when enabling HTTPS in Vite, it also enables HTTP/2
357+
// however, undici has not yet enabled HTTP/2 by default: https://github.com/nodejs/undici/issues/2750
358+
// we set a no-op proxy config to force Vite to downgrade to TLS-only
359+
// see https://vitejs.dev/config/#server-https
360+
if ((config.server.https || vite_basic_ssl) && !config.server.proxy) {
361+
config.server.proxy = {};
362+
}
363+
364+
if ((config.preview.https || vite_basic_ssl) && !config.preview.proxy) {
365+
config.preview.proxy = {};
366+
}
367+
352368
vite_config = config;
353369
}
354370
};

0 commit comments

Comments
 (0)