| 11 | const startTime = Date.now(); |
| 12 | |
| 13 | const checkServer = () => { |
| 14 | const req = http.get(`http://localhost:${port}/api/health`, (res) => { |
| 15 | if (res.statusCode === 200) { |
| 16 | resolve(); |
| 17 | } else { |
| 18 | if (Date.now() - startTime > timeout) { |
| 19 | reject(new Error(`Server did not start within ${timeout}ms`)); |
| 20 | } else { |
| 21 | setTimeout(checkServer, 1000); |
| 22 | } |
| 23 | } |
| 24 | }); |
| 25 | |
| 26 | req.on('error', () => { |
| 27 | if (Date.now() - startTime > timeout) { |
| 28 | reject(new Error(`Server did not start within ${timeout}ms`)); |
| 29 | } else { |
| 30 | setTimeout(checkServer, 1000); |
| 31 | } |
| 32 | }); |
| 33 | }; |
| 34 | |
| 35 | checkServer(); |
| 36 | }); |