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

Already on GitHub? Sign in to your account

[fix] force Vite dev mode to use HTTP/1 for TLS #3553

Merged
merged 3 commits into from
Jan 26, 2022

Conversation

Conduitry
Copy link
Member

This fixes #3479 by adding a no-op server.proxy config to Vite in dev mode to force it to downgrade to TLS-only when HTTPS in enabled, rather than using HTTP/2. node-fetch's Request implementation did not like the HTTP/2 headers it was getting.

Arguably, we could only apply this server.proxy config when --https is enabled. I'd be up for making that change if someone else thinks it worthwhile.

I'm not entirely thrilled with this solution, but it seemed the best one at the moment. We may need to revisit how node-fetch deals with HTTP/2 headers at some point in the future.

I'm not sure how to test this nicely, so there isn't one, and I would appreciate someone else taking this for a spin.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

This avoids issues with node-fetch and HTTP/2 Request headers, which was
breaking our `dev --https`.
@changeset-bot
Copy link

changeset-bot bot commented Jan 26, 2022

🦋 Changeset detected

Latest commit: 9b01fd4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Jan 26, 2022

✔️ Deploy Preview for kit-demo canceled.

🔨 Explore the source changes: 9b01fd4

🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61f1afaafd4b3d00070440f6

@benmccann
Copy link
Member

Looks like there's an open issue in the node-fetch repo for HTTP/2 support: node-fetch/node-fetch#342

@Conduitry
Copy link
Member Author

It sounds like we shouldn't be holding our breath for that. I'm not sure to what extent we actually need HTTP/2 support and to what extent we just need it to not complain about HTTP/2-style headers when instantiating Request instances. I'd rather not fork node-fetch at this point, although there eventually may be enough compelling reasons to do so.

In any case, I think the workaround in this PR is a reasonable solution for now. My main fear is that Vite will eventually change its behavior around server.proxy and HTTP/2, or that it will become smarter, and realize that server.proxy = {} doesn't really necessitate any changes. If that happens, I hope we have some other way of controlling HTTP/1 vs HTTP/2, because - besides the node-fetch thing - I'm thinking HTTP/2 will be introducing other unnecessary complexities into local development.

@Conduitry
Copy link
Member Author

I've gone ahead and made the change I mentioned in the OP - I'm now only setting server.proxy to {} when server.https is present and server.proxy is absent.

@nstuyvesant
Copy link
Contributor

From my perspective, this is a good short-term fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

https option not working in svelte-kit next.236
4 participants