|
|
@@ -35,6 +35,72 @@ name-mismatch error on an unrelated tenant's hostname.
|
|
|
If TLS is configured and cannot be set up, the server REFUSES TO START rather
|
|
|
than serving plain HTTP on a port callers reach over https.
|
|
|
|
|
|
+## Static files: serving a project's own assets
|
|
|
+
|
|
|
+OFF by default and it needs TWO independent things, neither of which implies
|
|
|
+the other: the request must arrive on a hostname registered to the project,
|
|
|
+AND that project must have static serving explicitly enabled. A project may
|
|
|
+hold a hostname and serve nothing; a project may hold files and no hostname, in
|
|
|
+which case they stay private.
|
|
|
+
|
|
|
+It is UNAUTHENTICATED, because a browser fetching an image carries no
|
|
|
+credential. That is why enabling it is an act rather than an inherited state:
|
|
|
+turning it on publishes files that were private a moment earlier.
|
|
|
+
|
|
|
+- `GET /api/v1/projects/{p}/settings/static` (admin)
|
|
|
+- `PUT /api/v1/projects/{p}/settings/static` (admin) - body
|
|
|
+ `{"enabled": bool, "mount": "/", "index": "index.html", "cache_control": "public, max-age=300"}`
|
|
|
+
|
|
|
+`mount` is where the tree appears (`/` or `/something`). A mount under `/api`,
|
|
|
+`/fn` or `/healthz` is refused 422 `invalid_mount`: **the service's own
|
|
|
+surfaces always win**, whatever the mount, so a `/` mount never shadows the API.
|
|
|
+
|
|
|
+`index` is the SPA fallback for a path matching no file. **`""` is a VALUE
|
|
|
+meaning "no fallback - an unmatched path answers a plain 404", not an absent
|
|
|
+key.** An absent key leaves the stored value alone; a present empty string is
|
|
|
+stored.
|
|
|
+
|
|
|
+### The path a file is served at comes from its METADATA, not its name
|
|
|
+
|
|
|
+File names are a single path segment, so `assets/index-a1b2.js` cannot be a
|
|
|
+name. The served path lives in the database's per-file metadata under `path`:
|
|
|
+
|
|
|
+ POST /api/v1/projects/{p}/files with header X-File-Path: /img/logo.png
|
|
|
+
|
|
|
+**A file with no `path` metadata is not reachable over the static mount at
|
|
|
+all** - it stays private, addressable only through the authenticated files
|
|
|
+route. Absence means private; it never falls back to serving by name. A PUT
|
|
|
+replaces rather than merges, so re-uploading without the header makes a file
|
|
|
+private again.
|
|
|
+
|
|
|
+### Caching, and what is not implemented
|
|
|
+
|
|
|
+`ETag` is the stored checksum, as a strong validator. `If-None-Match` is
|
|
|
+honoured with a 304 carrying the ETag and `Cache-Control` and no body - which
|
|
|
+is the highest-value part of this for an SPA, since the alternative is
|
|
|
+re-sending every chunk on every load.
|
|
|
+
|
|
|
+`Content-Type` is the type stored at upload and is NEVER sniffed from the
|
|
|
+extension. A file stored with the wrong type is a tenant's to fix; guessing
|
|
|
+would make the stored value a lie that sometimes works.
|
|
|
+
|
|
|
+**GET only. HEAD is not implemented and answers 404.** There is no directory
|
|
|
+listing, ever, and a path matching no file answers the same 404 whether the
|
|
|
+project has one file or a thousand.
|
|
|
+
|
|
|
+Per-file ceiling is `max_file_bytes` (global setting, default 2 MiB) - the same
|
|
|
+number that bounds storage, deliberately not a second number meaning nearly the
|
|
|
+same thing. The per-run 1 MiB `ctx.files` limit does NOT apply here: that bounds
|
|
|
+what one function may load into a JS heap, and this path never enters the
|
|
|
+runtime.
|
|
|
+
|
|
|
+**Known cost, until database 2.21.8 is everywhere:** resolving an alias needs
|
|
|
+the per-file metadata, which older servers omit from the files LISTING while
|
|
|
+returning it from `getFileInfo`. The lookup therefore re-fetches per record
|
|
|
+when the listing comes back empty, capped at 5000 records. A fast path keeps
|
|
|
+the common case at two calls. This disappears by itself on 2.21.8 with no
|
|
|
+change to any caller.
|
|
|
+
|
|
|
## Hostnames: the short path form
|
|
|
|
|
|
Every project-scoped route accepts TWO shapes:
|