ui/backend_probe.svelte.ts

Backend liveness probe — whether the app's backend is serving, read from its /health route.

AuthState.check_session can't tell a backend that's down from a logged-out caller, so a login gate probes /health to say the backend is needed instead of showing a login form that can't work. Only the health reply counts: a static server or an SPA fallback answering every path with a 200 HTML page is not a backend, and neither is a network error. Browser-safe — no server imports.

view source

Declarations
#

7 declarations

BACKEND_PROBE_ABORTED
#

ui/backend_probe.svelte.ts view source

"aborted" import {BACKEND_PROBE_ABORTED} from '@fuzdev/fuz_app/ui/backend_probe.svelte.js';

The refusal for a probe its caller's signal aborted — a cancel, not a timeout.

BACKEND_PROBE_NOT_HEALTH
#

ui/backend_probe.svelte.ts view source

"not a health response" import {BACKEND_PROBE_NOT_HEALTH} from '@fuzdev/fuz_app/ui/backend_probe.svelte.js';

The refusal for a 2xx whose body isn't the health reply.

BACKEND_PROBE_TIMEOUT_MS
#

ui/backend_probe.svelte.ts view source

10000 import {BACKEND_PROBE_TIMEOUT_MS} from '@fuzdev/fuz_app/ui/backend_probe.svelte.js';

How long the default fetch waits for the health reply before the probe reads as down.

BackendProbe
#

ui/backend_probe.svelte.ts view source

import {BackendProbe} from '@fuzdev/fuz_app/ui/backend_probe.svelte.js';

Reactive probe_backend state for a login gate. reachable stays null until a probe settles — through SSR and prerender too, so a gate that waits on it renders its pending notice there.

examples

const backend = new BackendProbe(); if (BROWSER) void backend.probe(); // in markup: `backend.reachable === null` → checking; `!backend.reachable` → down

probing

Whether a probe is in flight.

type boolean

$state.raw

reachable

Whether the backend answered the last settled probe — null before one settles.

type boolean | null

$state.raw

error

Why the last settled probe failed — null when it succeeded or none has settled.

type string | null

$state.raw

constructor

type new (options?: OmitStrict<BackendProbeOptions, "signal"> | undefined): BackendProbe

options?

the health fetch and the default fetch's timeout; no signal, since one that aborted would fail every later probe as BACKEND_PROBE_ABORTED

type OmitStrict<BackendProbeOptions, "signal">
optional

probe

Probe the backend and record the answer. A probe started while another is in flight supersedes it: only the latest one's answer is recorded.

type (): Promise<boolean>

returns Promise<boolean>

whether the backend answered this probe

BackendProbeOptions
#

ui/backend_probe.svelte.ts view source

BackendProbeOptions import type {BackendProbeOptions} from '@fuzdev/fuz_app/ui/backend_probe.svelte.js';

Options for probe_backend; BackendProbe takes all but signal.

fetch_health?

Fetches the health route — defaults to fetch(HEALTH_PATH) with a timeout_ms signal, combined with signal when given. An injected fetch owns its own signal.

type (): Promise<Response>

returns Promise<Response>

timeout_ms?

How long the default fetch waits for the reply and its body — defaults to BACKEND_PROBE_TIMEOUT_MS; unused when fetch_health is injected.

type number

signal?

Cancels the default fetch, alongside its timeout; unused when fetch_health is injected. A probe that fails once it is aborted reports BACKEND_PROBE_ABORTED — whatever the signal's reason, so a deadline belongs in timeout_ms.

type AbortSignal

BackendProbeResult
#

ui/backend_probe.svelte.ts view source

BackendProbeResult

type ({ ok: true; } & object) | ({ ok: false; } & { error: string; })

import type {BackendProbeResult} from '@fuzdev/fuz_app/ui/backend_probe.svelte.js';

probe_backend's answer: live, or why not.

probe_backend
#

ui/backend_probe.svelte.ts view source

(options?: BackendProbeOptions | undefined): Promise<BackendProbeResult> import {probe_backend} from '@fuzdev/fuz_app/ui/backend_probe.svelte.js';

Probe whether the backend is serving: its health route must answer 2xx with a body that parses as HealthResponse. A timeout while the reply or its body is read reads as down — naming timeout_ms only when the default fetch timed out, since an injected fetch_health owns its own signal. A failure once the caller's signal aborted reports BACKEND_PROBE_ABORTED, not a timeout or a down backend. A body that isn't JSON is BACKEND_PROBE_NOT_HEALTH; any other failure reading it reports the error.

options?

the health fetch, the default fetch's timeout, and a signal to cancel it

optional

returns

Promise<BackendProbeResult>

{ok: true} when the backend answered, else the reason it didn't

Depends on
#