Skip to content

Commit f2b9ba9

Browse files
acn-ericlawclaude
andcommitted
feat(host): static web content from resources/public - the engines' static.html.folder, served for the paths nothing else claims
The host serves the files of static.html.folder (the Java engine's key) from resources/public next to the application file by default (the Rust engine's location, under the packs' resources rule) for any GET or HEAD that no host path, extension route or function claims: index.html for a folder, so a folder's index.html replaces the embedded landing page at /; the content type by extension from the engines' table; an ETag with 304 on If-None-Match; Cache-Control: no-cache for HTML; a hidden segment, a symbolic link out of the folder or anything that is not a regular file not found, in the engines' error shape. AppConfig.app_dir names the application file's folder. Docs, README and CHANGELOG updated; the 2026-08-24 "no static file service" note withdrawn. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 264b5ec commit f2b9ba9

11 files changed

Lines changed: 485 additions & 13 deletions

‎CHANGELOG.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@
136136
mode, the PostgreSQL statements on a recording fake, the hooks and the boot; a live PostgreSQL gated on
137137
`AGENT_QUESTION_TEST_URL`). **Upgrade note:** none - a new application; the main flow lists it in `ask.channels`.
138138

139+
7. **Static web content: the host serves the files of `static.html.folder` - the Java engine's key, with the Rust
140+
engine's location as its default, `resources/public` next to the application file (Eric, 2026-11-20).** A `GET` or
141+
`HEAD` that no host path, extension route or function claims is answered with the file the path names inside the
142+
folder, `index.html` for a folder, so a folder's `index.html` replaces the embedded landing page at `/` while
143+
`/info`, `/health` and the other host paths stay the host's. The content type comes from the engines' table by
144+
extension (`text/javascript`, `text/css`, `image/svg+xml`, the fonts and images a bundle ships;
145+
`application/octet-stream` otherwise); every file carries an ETag and answers `If-None-Match` with 304, and
146+
`text/html` is served `Cache-Control: no-cache`, so a redeployed page is revalidated while hashed assets stay
147+
cached. A path with a hidden segment (one starting with `.`, so `..` too), a symbolic link that leaves the folder,
148+
or anything that is not a regular file is not found, in the engines' error shape as before. A relative value of
149+
the key is under the application file's folder, never the working directory (`AppConfig.app_dir` names that
150+
folder now); `file:` prefixes an absolute path as in the Java engine; an empty value turns the service off. Not
151+
ported: the Java engine's static-content filter, its `no-cache-pages` list and its `mime.types` section. The
152+
first consumer is the agent-question app's React front-end, built in the Node.js pack and deployed into both
153+
packs' `resources/public`; the 2026-08-24 note that the wrappers serve no static files is withdrawn.
154+
139155
### Fixed
140156

141157
1. **The agent-question app keeps the first accepted decision when two devices decide one card at the same moment**

‎README.md‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ The same conventions as the engines, so a polyglot installation stays uniform:
138138
| `rest.server.port` | Event API port | `8085` |
139139
| `log.format` | `text`, `json` (pretty-printed) or `compact` (single-line JSONL) | `text` |
140140
| `log.level` | log level (`LOG_LEVEL` env var wins) | `INFO` |
141+
| `static.html.folder` | the folder of static web content the host serves (HTML, CSS, JS, images), relative to the application file | `resources/public` |
141142

142143
Configuration lives in the `resources` folder next to the application file, mirroring the
143144
engines' classpath resources: `resources/application.yml` (or `.yaml` / `.properties`) beside
@@ -167,7 +168,7 @@ Kubernetes probes and dashboards treat a Python app exactly like a Java or Rust
167168

168169
| Endpoint | Purpose |
169170
|----------|---------|
170-
| `GET /` | minimal index page linking the endpoints below |
171+
| `GET /` | the static folder's `index.html`, else a minimal index page linking the endpoints below |
171172
| `GET /info` | app identity, runtime, origin id, start time, uptime |
172173
| `GET /info/routes` | registered routes split by visibility, with instance counts |
173174
| `GET /env` | selected environment variables and configuration parameters |
@@ -196,6 +197,21 @@ unknown paths answer the engines' error shape
196197
Kubernetes wiring: point `livenessProbe` at `/livenessprobe` and `readinessProbe` at
197198
`/health`.
198199

200+
## Static content
201+
202+
The host serves the files of `static.html.folder` — the Java engine's key, with the Rust engine's
203+
location as its default, `resources/public` next to the application file — for any `GET` or `HEAD`
204+
that no host path, extension route or function claims, so an application can ship a web front-end
205+
beside its functions the way the engines' Playground does. A folder is served as its `index.html`,
206+
so `resources/public/index.html` replaces the landing page at `/`. The content type follows the
207+
engines' table by extension (`text/javascript`, `text/css`, `image/svg+xml`, fonts and images;
208+
`application/octet-stream` otherwise); every file carries an ETag and answers `If-None-Match` with
209+
304, and HTML is served `Cache-Control: no-cache`, so a redeployed page is revalidated while hashed
210+
assets stay cached. A hidden entry, a `..` segment, a symbolic link that leaves the folder or
211+
anything that is not a regular file is not found, in the engines' error shape. A relative value of
212+
the key is under the application file's folder, never the working directory; `file:` prefixes an
213+
absolute path as in the Java engine; an empty value turns the service off.
214+
199215
## Wire compatibility
200216

201217
The codec implements the

‎docs/guides/config-logging-actuators.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ The host serves the engines' endpoints on the same port as `/api/event`:
111111

112112
| Endpoint | Purpose |
113113
|----------|---------|
114-
| `GET /` | minimal index page linking the endpoints below |
114+
| `GET /` | the static folder's `index.html`, else a minimal index page linking the endpoints below |
115115
| `GET /info` | app identity, runtime, origin id, start time, uptime |
116116
| `GET /info/routes` | registered routes split by visibility, with instance counts |
117117
| `GET /env` | selected environment variables and configuration parameters (opt-in lists) |
@@ -141,6 +141,23 @@ async def health_check(headers: dict[str, str], _body: Body):
141141
Optional dependencies never change the overall status; mandatory ones decide
142142
`UP`/`DOWN`, and the most recent outcome drives `/livenessprobe`.
143143

144+
## Static content — the engines' `public` folder
145+
146+
The host serves the files of `static.html.folder` for any `GET` or `HEAD` that no host path,
147+
extension route or function claims — the Java engine's key, with the Rust engine's location as
148+
its default: `resources/public` next to the application file, under the resources rule above (a
149+
relative value is under the application file's folder, never the working directory; `file:`
150+
prefixes an absolute path as in the Java engine; an empty value turns the service off). A folder
151+
is served as its `index.html`, so `resources/public/index.html` replaces the landing page at `/`
152+
while `/info`, `/health` and the other host paths stay the host's. The content type follows the
153+
engines' table by extension — `text/javascript`, `text/css`, `image/svg+xml`, the fonts and images
154+
a bundle ships — and is `application/octet-stream` otherwise; every file carries an ETag and
155+
answers `If-None-Match` with 304, and HTML is served `Cache-Control: no-cache`, so a redeployed
156+
page is revalidated while hashed assets stay cached. Never found, in the engines' error shape: a
157+
hidden entry (a segment starting with `.`, so `..` too), a symbolic link that leaves the folder,
158+
anything that is not a regular file. Not ported from the Java engine: the static-content filter,
159+
the `no-cache-pages` list and the `mime.types` section.
160+
144161
## Kubernetes wiring
145162

146163
```yaml

‎docs/guides/configuration-reference.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ keywords: [configuration, reference, keys, substitution, overrides]
3333
| `show.application.properties` | opt-in list of configuration keys shown by `/env` | (empty) |
3434
| `mandatory.health.dependencies` | routes of health check functions that decide `/health` | (empty) |
3535
| `optional.health.dependencies` | health check routes reported but never affecting status | (empty) |
36+
| `static.html.folder` | the folder of static web content the host serves for the paths nothing else claims — relative to the application file's folder ([guide](config-logging-actuators.md#static-content-the-engines-public-folder)) | `resources/public` |
3637
| `otel.forwarding` | the OpenTelemetry forwarder's master switch ([guide](config-logging-actuators.md#distributed-tracing-the-opentelemetry-forwarder-opt-in)) | `false` |
3738
| `otel.exporter.otlp.endpoint` | the OTLP/HTTP traces URL including the signal path | `http://localhost:4318/v1/traces` |
3839
| `otel.exporter.otlp.headers` | request headers, `k=v` or `k: v`, comma-separated (re-read per export) | (none) |

‎docs/guides/http-surface-reference.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ charset=utf-8` (the engines' default-serializer presentation).
3232

3333
| Endpoint | Content type | Shape |
3434
|----------|--------------|-------|
35-
| `GET /` | `text/html` | minimal index page linking the endpoints |
35+
| `GET /` | `text/html` | the static folder's `index.html`, else a minimal index page linking the endpoints |
3636
| `GET /info` | JSON | `{app{name,version,description}, runtime{language,python,mercury_composable}, origin, time{start,current}, up_time}` |
3737
| `GET /info/routes` | JSON | `{app, routing{public{route: instances}, private{...}}}` |
3838
| `GET /env` | JSON | `{app, env{environment{...}, properties{...}}}` (opt-in lists) |
@@ -47,6 +47,16 @@ reports `status_code: 404` with `Please check - Route X not found`.
4747
uuid (the Java reference engine's format).
4848
- `up_time` — the engines' rendering (`59 seconds`, `1 minute 1 second`, …).
4949

50+
## Static content
51+
52+
A `GET` or `HEAD` of any other path is answered with the file it names inside `static.html.folder`
53+
(`resources/public` next to the application file by default; `index.html` for a folder) when there
54+
is one: the content type by extension from the engines' table, an `ETag` (`If-None-Match` answers
55+
304 with no body) and, for HTML, `Cache-Control: no-cache`. A path that names nothing — including a
56+
hidden entry, a link out of the folder or a folder without an index page — falls through to the
57+
error signature below. See the
58+
[guide](config-logging-actuators.md#static-content-the-engines-public-folder).
59+
5060
## Error signature (host-level)
5161

5262
Unknown paths and non-GET methods on known paths answer the engines' shape —

‎src/mercury_composable/actuator.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ async def health(headers: dict[str, str], _body: Body) -> Body:
6363
HEALTH_TIMEOUT_MS = 10000 # engine value for the type=health probe
6464
UNHEALTHY = "Unhealthy. Please check '/health' endpoint."
6565

66-
# The engines' minimal landing page (platform-core public/index.html style);
67-
# the wrappers embed it - no static file service by design.
66+
# The engines' minimal landing page (platform-core public/index.html style), embedded: served
67+
# at / unless the static content folder (static_content.py) has an index.html of its own.
6868
INDEX_HTML = """<!DOCTYPE html>
6969
<html>
7070
<body>

‎src/mercury_composable/config.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def __init__(self, path: str | None = None, argv: list[str] | None = None,
104104
self._overrides: dict[str, Any] = parse_d_args(sys.argv[1:] if argv is None else argv)
105105
self._source = "none"
106106
self._resources_dir: str | None = None
107+
self._app_dir: str | None = app_dir if app_dir is not None else main_script_dir()
107108
if path:
108109
if not os.path.isfile(path):
109110
raise FileNotFoundError(f"Configuration file not found - {path}")
@@ -146,6 +147,13 @@ def resources_dir(self) -> str | None:
146147
None when there is neither."""
147148
return self._resources_dir
148149

150+
@property
151+
def app_dir(self) -> str | None:
152+
"""The application file's folder - the ``app_dir`` given (the CLI passes the application
153+
file's), else the folder of the script Python ran; None in an interactive session. The
154+
``resources`` folder and the static content folder are resolved under it."""
155+
return self._app_dir
156+
149157
def set(self, key: str, value: Any) -> None:
150158
"""Runtime override, checked first on every read (f:setConfig analog)."""
151159
if not key or not str(key).strip():

‎src/mercury_composable/server.py‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
)
5959
from .log import get_logger
6060
from .registry import FunctionRegistry, ServiceDef, default_registry
61+
from .static_content import StaticContent, resolve_folder
6162
from .trace import MY_CID_TAG, MY_CORRELATION_ID
6263

6364
OCTET_STREAM = "application/octet-stream"
@@ -223,6 +224,9 @@ class EventApiServer:
223224
def __init__(self, registry: FunctionRegistry | None = None):
224225
self.registry = registry or default_registry
225226
self.actuator = Actuator(self.registry)
227+
# the static content folder is resolved from the configuration at construction, as the
228+
# Actuator's settings are
229+
self.static = StaticContent(resolve_folder(app_config()))
226230

227231
async def handle_event(self, request: web.Request) -> web.StreamResponse:
228232
raw = await request.read()
@@ -420,24 +424,33 @@ async def _next_segment(response: web.StreamResponse,
420424

421425
def create_app(self, routes: Iterable[RouteMounter] = ()) -> web.Application:
422426
"""The Event API application: ``POST /api/event``, the actuator paths, then the routes
423-
of the extensions given (``Platform.add_routes``) and, last, the catch-all that answers
424-
the engines' error shape - so the host's paths always win and an extension's path wins
425-
over the catch-all."""
427+
of the extensions given (``Platform.add_routes``), then the static content folder for a
428+
GET or HEAD and, last, the catch-all that answers the engines' error shape - so the host's
429+
paths always win, an extension's path wins over a file and a file wins over the catch-all.
430+
A folder's ``index.html`` replaces the engines' landing page at ``/``."""
426431
app = web.Application(client_max_size=16 * 1024 * 1024)
427432
app.router.add_post("/api/event", self.handle_event)
428-
# the engines' landing page + actuator endpoints (see actuator.py)
429-
for path in ("/", "/info", "/info/routes", "/env", "/health", "/livenessprobe"):
433+
# the engines' landing page (or the static folder's index.html) + actuator endpoints
434+
# (see actuator.py)
435+
app.router.add_get("/", self.handle_other)
436+
for path in ("/info", "/info/routes", "/env", "/health", "/livenessprobe"):
430437
app.router.add_get(path, self.actuator.handle)
431438
# an extension's own routes - a reply page, a stream a browser holds - registered
432439
# after the host's and before the catch-all
433440
for mount in routes:
434441
mount(app)
435-
# any other path or method answers the engines' error shape, not
436-
# aiohttp's default text page (exact routes above win - they are
442+
# any other path: a static file for a GET or HEAD that names one, else the engines'
443+
# error shape, not aiohttp's default text page (exact routes above win - they are
437444
# registered first)
438-
app.router.add_route("*", "/{unknown:.*}", self.actuator.handle)
445+
app.router.add_route("*", "/{unknown:.*}", self.handle_other)
439446
return app
440447

448+
async def handle_other(self, request: web.Request) -> web.StreamResponse:
449+
"""A path no route claimed, and ``/``: the static folder's file (``index.html`` for a
450+
folder) when a GET or HEAD names one, else the actuator - the landing page at ``/``, the
451+
engines' error shape elsewhere."""
452+
return self.static.serve(request) or await self.actuator.handle(request)
453+
441454

442455
class Platform:
443456
"""Runs the Event API host for the default (or a given) registry."""

0 commit comments

Comments
 (0)