zitejs 0.10.0-start.0 → 0.10.0-start.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -45,10 +45,12 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
45
45
|
const node_url_1 = require("node:url");
|
|
46
46
|
// Only the host can set x-zite-* in production: the front strips them from public traffic.
|
|
47
47
|
const DESCRIBE_HEADERS = { "x-zite-invoke": "describe" };
|
|
48
|
+
// Not "localhost": it can resolve to ::1 for vite's listen and to 127.0.0.1 for fetch.
|
|
49
|
+
const HOST = "127.0.0.1";
|
|
48
50
|
const freePort = () => new Promise((resolve, reject) => {
|
|
49
51
|
const server = (0, node_net_1.createServer)();
|
|
50
52
|
server.once("error", reject);
|
|
51
|
-
server.listen(0, () => {
|
|
53
|
+
server.listen(0, HOST, () => {
|
|
52
54
|
const { port } = server.address();
|
|
53
55
|
server.close(() => resolve(port));
|
|
54
56
|
});
|
|
@@ -58,7 +60,7 @@ const freePort = () => new Promise((resolve, reject) => {
|
|
|
58
60
|
async function describeInWorkerd(appDir) {
|
|
59
61
|
const port = await freePort();
|
|
60
62
|
// Its own process group, so stopping it also stops vite and workerd under npx.
|
|
61
|
-
const preview = (0, node_child_process_1.spawn)("npx", ["--no-install", "vite", "preview", "--port", String(port), "--strictPort"], {
|
|
63
|
+
const preview = (0, node_child_process_1.spawn)("npx", ["--no-install", "vite", "preview", "--host", HOST, "--port", String(port), "--strictPort"], {
|
|
62
64
|
cwd: appDir,
|
|
63
65
|
stdio: ["ignore", "ignore", "pipe"],
|
|
64
66
|
detached: true,
|
|
@@ -69,7 +71,7 @@ async function describeInWorkerd(appDir) {
|
|
|
69
71
|
const deadline = Date.now() + 60_000;
|
|
70
72
|
while (true) {
|
|
71
73
|
try {
|
|
72
|
-
const response = await fetch(`http
|
|
74
|
+
const response = await fetch(`http://${HOST}:${port}/`, { headers: DESCRIBE_HEADERS });
|
|
73
75
|
// Right after start, preview can answer before the Worker does; only the
|
|
74
76
|
// app's own describe answer is JSON.
|
|
75
77
|
if (response.ok && response.headers.get("content-type")?.includes("application/json")) {
|
|
@@ -5,10 +5,12 @@ import path from "node:path";
|
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
// Only the host can set x-zite-* in production: the front strips them from public traffic.
|
|
7
7
|
const DESCRIBE_HEADERS = { "x-zite-invoke": "describe" };
|
|
8
|
+
// Not "localhost": it can resolve to ::1 for vite's listen and to 127.0.0.1 for fetch.
|
|
9
|
+
const HOST = "127.0.0.1";
|
|
8
10
|
const freePort = () => new Promise((resolve, reject) => {
|
|
9
11
|
const server = createServer();
|
|
10
12
|
server.once("error", reject);
|
|
11
|
-
server.listen(0, () => {
|
|
13
|
+
server.listen(0, HOST, () => {
|
|
12
14
|
const { port } = server.address();
|
|
13
15
|
server.close(() => resolve(port));
|
|
14
16
|
});
|
|
@@ -18,7 +20,7 @@ const freePort = () => new Promise((resolve, reject) => {
|
|
|
18
20
|
async function describeInWorkerd(appDir) {
|
|
19
21
|
const port = await freePort();
|
|
20
22
|
// Its own process group, so stopping it also stops vite and workerd under npx.
|
|
21
|
-
const preview = spawn("npx", ["--no-install", "vite", "preview", "--port", String(port), "--strictPort"], {
|
|
23
|
+
const preview = spawn("npx", ["--no-install", "vite", "preview", "--host", HOST, "--port", String(port), "--strictPort"], {
|
|
22
24
|
cwd: appDir,
|
|
23
25
|
stdio: ["ignore", "ignore", "pipe"],
|
|
24
26
|
detached: true,
|
|
@@ -29,7 +31,7 @@ async function describeInWorkerd(appDir) {
|
|
|
29
31
|
const deadline = Date.now() + 60_000;
|
|
30
32
|
while (true) {
|
|
31
33
|
try {
|
|
32
|
-
const response = await fetch(`http
|
|
34
|
+
const response = await fetch(`http://${HOST}:${port}/`, { headers: DESCRIBE_HEADERS });
|
|
33
35
|
// Right after start, preview can answer before the Worker does; only the
|
|
34
36
|
// app's own describe answer is JSON.
|
|
35
37
|
if (response.ok && response.headers.get("content-type")?.includes("application/json")) {
|