MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / waitForHttp

Function waitForHttp

e2e/setup/boot.ts:83–102  ·  view source on GitHub ↗
(
  url: string,
  options: { readonly timeoutMs?: number; readonly expectRedirect?: boolean } = {},
)

Source from the content-addressed store, hash-verified

81};
82
83export const waitForHttp = async (
84 url: string,
85 options: { readonly timeoutMs?: number; readonly expectRedirect?: boolean } = {},
86): Promise<void> => {
87 const deadline = Date.now() + (options.timeoutMs ?? 90_000);
88 let lastError: unknown;
89 while (Date.now() < deadline) {
90 try {
91 const response = await fetch(url, { redirect: "manual" });
92 // During a cold vite compile /api/* falls back to the SPA's 200 HTML —
93 // expectRedirect waits for the real handler (302) instead.
94 if (options.expectRedirect ? response.status === 302 : response.status < 500) return;
95 lastError = new Error(`status ${response.status}`);
96 } catch (error) {
97 lastError = error;
98 }
99 await new Promise((resolve) => setTimeout(resolve, 400));
100 }
101 throw new Error(`timed out waiting for ${url}: ${String(lastError)}`);
102};
103
104/**
105 * Reboot DOWN-GATE: wait until `url` stops answering (fetch rejects — connection

Callers 15

setupFunction · 0.90
bootCloudFunction · 0.90
bootCloudflareFunction · 0.90
setupCliTargetFunction · 0.90
runSelfhostContainerFunction · 0.90
setupFunction · 0.90
setupFunction · 0.90
setupFunction · 0.90
bootMotelFunction · 0.90
bootSelfhostFunction · 0.90
boot-stack.tsFile · 0.90
cliTargetFunction · 0.90

Calls 1

fetchFunction · 0.50

Tested by 4

startPlainViteDevFunction · 0.72
runSupervisedPortSettingFunction · 0.72
runFunction · 0.72