23 lines
684 B
JavaScript
23 lines
684 B
JavaScript
const http = require("http");
|
|
const { loadEnvFromFile } = require("../electron/load-env");
|
|
|
|
const root = require("path").join(__dirname, "..");
|
|
const port = parseInt(process.env.API_PORT || String(loadEnvFromFile(root).API_PORT), 10);
|
|
const url = `http://127.0.0.1:${port}/api/health`;
|
|
const maxAttempts = 60;
|
|
|
|
function tick(attempt) {
|
|
http
|
|
.get(url, (res) => {
|
|
if (res.statusCode === 200) process.exit(0);
|
|
else if (attempt >= maxAttempts) process.exit(1);
|
|
else setTimeout(() => tick(attempt + 1), 500);
|
|
})
|
|
.on("error", () => {
|
|
if (attempt >= maxAttempts) process.exit(1);
|
|
else setTimeout(() => tick(attempt + 1), 500);
|
|
});
|
|
}
|
|
|
|
tick(0);
|