Skip to content

fix: set no-op proxy config to get Vite HTTPS working #12907

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-walls-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

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
16 changes: 16 additions & 0 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,22 @@ async function kit({ svelte_config }) {
* Stores the final config.
*/
configResolved(config) {
// we search for this plugin by name because we can't detect it
// since it doesn't directly modify the https config unlike the mkcert plugin
const vite_basic_ssl = config.plugins.find(({ name }) => name === 'vite:basic-ssl');

// by default, when enabling HTTPS in Vite, it also enables HTTP/2
// however, undici has not yet enabled HTTP/2 by default: https://github.com/nodejs/undici/issues/2750
// we set a no-op proxy config to force Vite to downgrade to TLS-only
// see https://vitejs.dev/config/#server-https
if ((config.server.https || vite_basic_ssl) && !config.server.proxy) {
config.server.proxy = {};
}

if ((config.preview.https || vite_basic_ssl) && !config.preview.proxy) {
config.preview.proxy = {};
}

vite_config = config;
}
};
Expand Down
Loading