-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwait-for-vite.js
More file actions
59 lines (46 loc) · 1.42 KB
/
wait-for-vite.js
File metadata and controls
59 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
/**
* Wait for Vite dev server to be ready before Tauri starts
* This prevents white screen issues by ensuring the server is up
*/
const http = require('http');
const PORT = 3000;
const HOST = '127.0.0.1';
const MAX_RETRIES = 30;
const RETRY_DELAY = 1000; // 1 second
function checkServer() {
return new Promise((resolve, reject) => {
const req = http.get(`http://${HOST}:${PORT}`, (res) => {
resolve(res.statusCode === 200 || res.statusCode === 304);
});
req.on('error', (err) => {
reject(err);
});
req.setTimeout(2000, () => {
req.destroy();
reject(new Error('Request timeout'));
});
});
}
async function waitForVite() {
console.log(`Waiting for Vite dev server at http://${HOST}:${PORT}...`);
for (let i = 0; i < MAX_RETRIES; i++) {
try {
const isReady = await checkServer();
if (isReady) {
console.log(`✅ Vite dev server is ready at http://${HOST}:${PORT}`);
process.exit(0);
}
} catch (err) {
// Server not ready yet
}
if (i < MAX_RETRIES - 1) {
process.stdout.write(`Attempt ${i + 1}/${MAX_RETRIES}...\r`);
await new Promise(resolve => setTimeout(resolve, RETRY_DELAY));
}
}
console.error(`❌ Vite dev server did not become ready after ${MAX_RETRIES} attempts`);
console.error(` Make sure Vite is running on http://${HOST}:${PORT}`);
process.exit(1);
}
waitForVite();