-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron.js
46 lines (41 loc) · 967 Bytes
/
electron.js
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
const { spawn } = require('child_process');
const waitOn = require('wait-on');
const http = require('http');
const options = {
resources: ['http://localhost:3333'],
timeout: 60000,
};
function isServerReady(url) {
return new Promise((resolve, reject) => {
http
.get(url, (res) => {
if (res.statusCode === 200) {
resolve();
} else {
reject(new Error(`Server not ready: ${res.statusCode}`));
}
})
.on('error', reject);
});
}
const server = spawn('node', ['./server/router.js'], {
stdio: 'inherit',
shell: true,
});
waitOn(options)
.then(() => {
return isServerReady('http://localhost:3333');
})
.then(() => {
const electron = spawn('electron', ['.'], {
stdio: 'inherit',
shell: true,
});
electron.on('exit', (code) => {
server.kill();
});
})
.catch((err) => {
console.error('Error waiting for server:', err);
server.kill();
});