Skip to content

Commit dca4163

Browse files
authored
Support HTTPS and HTTP/2 (#9152)
1 parent f17ee08 commit dca4163

File tree

21 files changed

+257
-134
lines changed

21 files changed

+257
-134
lines changed

.changeset/cold-emus-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vite-plugin": minor
3+
---
4+
5+
Support HTTPS and HTTP/2. Configuring [`server.https`](https://vite.dev/config/server-options#server-https) and/or [`preview.https`](https://vite.dev/config/preview-options#preview-https) in your Vite config now works as expected. This was previously broken because Undici would add a `transfer-encoding` header for streamed responses. We now remove this header if the request uses HTTP/2.

packages/vite-plugin-cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"dependencies": {
4545
"@cloudflare/unenv-preset": "workspace:*",
46-
"@hattip/adapter-node": "^0.0.49",
46+
"@mjackson/node-fetch-server": "^0.6.1",
4747
"@rollup/plugin-replace": "^6.0.1",
4848
"get-port": "^7.1.0",
4949
"miniflare": "workspace:*",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { expect, test } from "vitest";
2+
import { page } from "../../../__test-utils__";
3+
4+
test("returns the correct home page", async () => {
5+
const content = await page.textContent("h1");
6+
expect(content).toBe("Vite + React");
7+
});

packages/vite-plugin-cloudflare/playground/spa-with-api/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
"scripts": {
66
"build": "vite build --app",
77
"build:custom-output-directories": "vite build --app -c ./vite.config.custom-output-directories.ts",
8+
"build:https": "vite build --app -c ./vite.config.https.ts",
89
"check:types": "tsc --build",
910
"dev": "vite dev",
11+
"dev:https": "vite dev -c ./vite.config.https.ts",
1012
"preview": "vite preview",
11-
"preview:custom-output-directories": "vite preview -c ./vite.config.custom-output-directories.ts"
13+
"preview:custom-output-directories": "vite preview -c ./vite.config.custom-output-directories.ts",
14+
"preview:https": "vite preview -c ./vite.config.https.ts"
1215
},
1316
"dependencies": {
1417
"react": "^19.0.0",
@@ -20,6 +23,7 @@
2023
"@cloudflare/workers-types": "^4.20250508.0",
2124
"@types/react": "^19.0.0",
2225
"@types/react-dom": "^19.0.0",
26+
"@vitejs/plugin-basic-ssl": "^2.0.0",
2327
"@vitejs/plugin-react": "^4.3.4",
2428
"typescript": "catalog:default",
2529
"vite": "catalog:vite-plugin",
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
22
"extends": ["@cloudflare/workers-tsconfig/base.json"],
3-
"include": ["vite.config.ts", "__tests__"]
3+
"include": [
4+
"vite.config.ts",
5+
"vite.config.custom-output-directories.ts",
6+
"vite.config.https.ts",
7+
"__tests__"
8+
]
49
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { cloudflare } from "@cloudflare/vite-plugin";
2+
import basicSsl from "@vitejs/plugin-basic-ssl";
3+
import react from "@vitejs/plugin-react";
4+
import { defineConfig } from "vite";
5+
6+
export default defineConfig({
7+
plugins: [
8+
react(),
9+
cloudflare({ inspectorPort: false, persistState: false }),
10+
basicSsl(),
11+
],
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect, test, vi } from "vitest";
2+
import { page } from "../../__test-utils__";
3+
4+
test("renders HTML stream", async () => {
5+
const heading = await page.textContent("h1");
6+
expect(heading).toBe("Streaming example");
7+
const finalChunk = await vi.waitUntil(() => page.textContent("#two"), {
8+
timeout: 5000,
9+
interval: 500,
10+
});
11+
expect(finalChunk).toBe("Chunk after 2 seconds");
12+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "../base-tests";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./base-tests";
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@playground/streaming",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "vite build",
7+
"build:https": "vite build -c ./vite.config.https.ts",
8+
"check:types": "tsc --build",
9+
"dev": "vite dev",
10+
"dev:https": "vite dev -c ./vite.config.https.ts",
11+
"preview": "vite preview",
12+
"preview:https": "vite preview -c ./vite.config.https.ts"
13+
},
14+
"devDependencies": {
15+
"@cloudflare/vite-plugin": "workspace:*",
16+
"@cloudflare/workers-tsconfig": "workspace:*",
17+
"@cloudflare/workers-types": "^4.20250507.0",
18+
"@vitejs/plugin-basic-ssl": "^2.0.0",
19+
"typescript": "catalog:default",
20+
"vite": "catalog:vite-plugin",
21+
"wrangler": "workspace:*"
22+
}
23+
}

0 commit comments

Comments
 (0)