-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait-for-react.js
More file actions
50 lines (41 loc) · 1.24 KB
/
wait-for-react.js
File metadata and controls
50 lines (41 loc) · 1.24 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
// wait-for-react.js
const http = require('http');
const { exec } = require('child_process');
let attempts = 0;
const maxAttempts = 30;
const checkInterval = 1000; // 1 second
console.log('Waiting for React server to start...');
function checkServerStatus() {
attempts++;
http.get('http://localhost:3002', (res) => {
if (res.statusCode === 200) {
console.log('React server is ready! Starting Electron...');
// Start Electron
const electron = exec('npm run electron-start');
electron.stdout.on('data', (data) => {
console.log(`Electron: ${data}`);
});
electron.stderr.on('data', (data) => {
console.error(`Electron error: ${data}`);
});
electron.on('close', (code) => {
console.log(`Electron process exited with code ${code}`);
process.exit(code);
});
} else {
retry();
}
}).on('error', () => {
retry();
});
}
function retry() {
if (attempts < maxAttempts) {
console.log(`Waiting for React server (attempt ${attempts}/${maxAttempts})...`);
setTimeout(checkServerStatus, checkInterval);
} else {
console.error('React server did not start in time. Giving up.');
process.exit(1);
}
}
checkServerStatus();