MCPcopy
hub / github.com/AutoMaker-Org/automaker / waitForServer

Function waitForServer

apps/ui/src/electron/server/backend-server.ts:183–208  ·  view source on GitHub ↗
(maxAttempts = 30)

Source from the content-addressed store, hash-verified

181 * Wait for server to be available
182 */
183export async function waitForServer(maxAttempts = 30): Promise<void> {
184 for (let i = 0; i < maxAttempts; i++) {
185 try {
186 await new Promise<void>((resolve, reject) => {
187 const req = http.get(`http://localhost:${state.serverPort}/api/health`, (res) => {
188 if (res.statusCode === 200) {
189 resolve();
190 } else {
191 reject(new Error(`Status: ${res.statusCode}`));
192 }
193 });
194 req.on('error', reject);
195 req.setTimeout(1000, () => {
196 req.destroy();
197 reject(new Error('Timeout'));
198 });
199 });
200 logger.info('Server is ready');
201 return;
202 } catch {
203 await new Promise((r) => setTimeout(r, 500));
204 }
205 }
206
207 throw new Error('Server failed to start');
208}
209
210/**
211 * Stop the backend server if running

Callers 2

handleAppReadyFunction · 0.90
startServerFunction · 0.85

Calls 2

destroyMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected