MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / isApiReachable

Function isApiReachable

apps/api/tests/health.test.ts:6–27  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4const BASE_URL = process.env.TEST_BASE_URL ?? "http://127.0.0.1:7330";
5
6const isApiReachable = async (): Promise<boolean> => {
7 try {
8 const res = await fetch(`${BASE_URL}/health`, {
9 signal: AbortSignal.timeout(500),
10 });
11
12 if (!res.ok) {
13 return false;
14 }
15
16 /*
17 * Strict content-type check so unrelated processes on the same port
18 * (Vite, nginx, etc. — common during local dev when the API isn't
19 * running) don't pass as "reachable" and crash the JSON parser below.
20 */
21 const contentType = res.headers.get("content-type") ?? "";
22
23 return contentType.includes("application/json");
24 } catch {
25 return false;
26 }
27};
28
29test("GET /health returns status ok", async () => {
30 if (!(await isApiReachable())) {

Callers 1

health.test.tsFile · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected