ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
spa_router.h File Reference

Single-page-app micro-routing + conditional UI streaming (PC_ENABLE_SPA_ROUTER). More...

#include "protocore_config.h"
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Detailed Description

Single-page-app micro-routing + conditional UI streaming (PC_ENABLE_SPA_ROUTER).

A single-page web UI does its own client-side routing: the browser navigates to /dashboard or /devices/42, but there is no such file on the device - the server must return the app shell (index.html) and let the JavaScript router take over, while still serving real asset files (/app.js, /style.css) and letting API calls (/api/...) fall through to their handlers. This is that routing decision: given a request path, return whether to serve the file, serve the shell, or pass through to the app.

The rule: a path under a configured API prefix passes through; a path whose last segment has a file extension (a dot) is a real asset request; anything else is a client route and gets the shell. Pure, zero heap, no stdlib, host-testable; the caller wires the result into serve_static / the router.

The fallback HMI

On a machine-control device the SPA is a convenience, not the contract. If the shell asset is missing (a half-finished upload, a wiped filesystem), the client will not run scripts, or the device itself is degraded, an operator still has to be able to see state and actuate something. So a client route can resolve to PC_SPA_SERVE_FALLBACK instead: a plain server-rendered control page needing no JavaScript and no asset files. The API prefix keeps passing through in that mode - a fallback page whose endpoints have stopped answering is decoration.

Conditional UI streaming

That page is assembled from fragments, each with a predicate, and streamed in caller-sized chunks: only the panels whose condition currently holds are emitted, and a page far larger than any single buffer never has to fit in RAM. The same streamer serves any conditional UI - showing an operator only the panels their role, or the machine's current state, warrants.

Definition in file spa_router.h.