SPB Git

Repository Public

map-distribution.md 7.0 KB 100 lines markdown

1# Map distribution (`/maps/v1`)23The site serves the signed region packages of ORIX Maps the same way it serves the model library of ORIX Astra4(`/astra/models/v1`): plain files, no account, no API key, no page. The contract is `docs/CATALOG_API.md` of the ORIX5Maps repository (section 2, "Server requirements"); the route is `src/app/maps/v1/[...path]/route.ts`, the tests are6`tests/maps.test.ts`.78The public page `/maps` (`/fr/maps`, `src/app/[locale]/maps/page.tsx`) lists the published regions for visitors. It reads9`catalog.json` and `regions/<id>.json` from the same directory through `src/lib/maps.ts` (tests:10`tests/maps-library.test.ts`), offers no link to a package, and shows an empty state when no catalogue is published.1112## Resources1314| `GET` / `HEAD` | File under the distribution root | `Content-Type` | `Cache-Control` |15|---|---|---|---|16| `/maps/v1/catalog.json` | `catalog.json` | `application/json` | `public, max-age=300` |17| `/maps/v1/regions/<id>.json` | `regions/<id>.json` | `application/json` | `public, max-age=300` |18| `/maps/v1/regions/<id>/versions.json` | `regions/<id>/versions.json` | `application/json` | `public, max-age=300` |19| `/maps/v1/files/<id>/<dataVersion>/<id>-<dataVersion>.orixmap` | same path | `application/vnd.orix.map` | `public, max-age=31536000, immutable, no-transform` |2021`<id>` is `[a-z0-9-]{1,64}`; `<dataVersion>` is a dotted decimal version (up to eight groups of digits). Every other22path answers 404, including `pins.json` (publisher state) and any other file placed in the directory.2324## Distribution directory2526`ORIX_MAPS_DIR` (default `~/apps-data/orix-maps`) + `/v1`, outside the deployment and outside git. It is written by27`orix-package publish` / `orix-package catalog` (ORIX Maps repository), which replace each file by a rename and write28`catalog.json` last; the route only reads.2930```text31~/apps-data/orix-maps/v1/catalog.json32~/apps-data/orix-maps/v1/regions/ca-qc-montreal.json33~/apps-data/orix-maps/v1/regions/ca-qc-montreal/versions.json34~/apps-data/orix-maps/v1/files/ca-qc-montreal/2026.11.24/ca-qc-montreal-2026.11.24.orixmap35~/apps-data/orix-maps/v1/pins.json            (never served)36```3738An empty or missing directory is a valid state: everything answers 404. Publishing needs no restart: documents are read39again when their modification time or size changes. Never overwrite a published package (its URL is cached as40immutable); new data is a new `dataVersion`. Packages signed with a development key must not be placed here.4142## Behaviour4344- **Listing rule.** A package is served only when the current `catalog.json` (`regions[].latest`) or the region's45  `versions.json` (`versions[]`) lists it with that exact `path`, a `downloadSize` and a 64-digit lowercase `sha256`,46  **and** the size on disk equals `downloadSize`. Otherwise 404. Removing a version from both documents withdraws it.47- **ETag.** Always strong: `"<sha256 hex>"`. For a package it is the listed `sha256` (packages are never hashed by the48  server: the bytes are only checked by size, the application verifies digest and signature). For a JSON document it is49  the SHA-256 of the file, computed once per (mtime, size).50- **`If-None-Match`** → `304` (list of tags, `*`, weak comparison), evaluated before `Range`.51- **`Range`** (packages, `GET` only): `bytes=a-b`, `bytes=a-` and the suffix form `bytes=-n` → `206` with52  `Content-Range` and `Content-Length`; a last byte past the end is clamped. A range starting at or after the end, or53  `bytes=-0` → `416` with `Content-Range: bytes */<size>`. A header that asks for several ranges, uses another unit or54  is malformed is **ignored** and the whole file is sent with `200` (RFC 9110 §14.2 allows a server to ignore `Range`).55  `HEAD` ignores `Range` and reports the full length.56- **`If-Range`**: the range is honoured only when the value is exactly the current strong ETag. Any other value (another57  tag, a weak tag, a date) → `200` with the whole file, even when the range itself would be unsatisfiable.58- **Headers on every answer**: `X-Content-Type-Options: nosniff`, `X-Robots-Tag: noindex`,59  `Access-Control-Allow-Origin: *`; `Accept-Ranges: bytes` on packages. Never60  `Set-Cookie`, never `Content-Encoding` (the site does not compress; `no-transform` asks the gateway not to compress a61  package either).62- **`Content-Length`: set by the route, not on the wire.** The handler sets `Content-Length` on every 200 and 20663  (the tests check it), but Next.js 16.4 removes `Content-Length` from every route-handler response64  (`FORBIDDEN_HEADERS` in `next/dist/server/send-response.js`) and sends the body with chunked transfer encoding; a65  `HEAD` answer carries no length either. The same holds for `/astra/models/v1`. Clients must take the size from the66  catalog (`downloadSize`) or from `Content-Range` (`bytes a-b/<total>`, which is delivered); a truncated transfer is67  still detected by the HTTP framing. Sending the header would need a response written outside the App Router (a Pages68  API route or the gateway).69- **Safety.** The URL must match one of the four shapes before the file system is touched; the resolved path70  (`realpath`) must stay under the resolved distribution root, so neither `..` nor a symbolic link can lead outside. A71  JSON document larger than 8 MiB (the client's own limit) is not served.72- **Rate limit.** 300 requests per 60 seconds and per client address (scope `orix-maps` of `lib/security/ratelimit`),73  then `429` with `Retry-After: <seconds until the window ends>`. A download costs one request per attempt or resume.74- **Errors.** An unexpected failure answers a bare `500` and logs nothing.7576Requests without a file extension that match none of the shapes (`/maps/v1/regions/x`) never reach the route: the locale77proxy rewrites them to the site's own 404 page (status 404, HTML), like any unknown page.7879## What is recorded about a download8081- **The route**: nothing. No log line, no counter, no database row, no file. (The anonymous download counters of82  `/download` do not apply here.)83- **The Next.js process** (`orix-web` under PM2, logs in `~/.pm2/logs/orix-web-{out,error}.log`): `next start` writes84  no access log. The output log holds start-up lines only; the error log holds stack traces of unexpected server85  errors, without address or headers.86- **In memory only**: the rate limiter keeps, per client address, a request count and the end of the current87  60-second window (`orix-maps:<address>`). It is never written to disk, is gone at every restart of `orix-web`, and88  expired entries are dropped when the table is pruned.89- **The gateway** (Caddy on the public server, in front of this node) terminates TLS and sees the address, the time,90  the URL and the size of every request. Whether and how long it logs them is its own configuration, outside this91  repository.9293## Operations9495```bash96mkdir -p ~/apps-data/orix-maps/v1                       # once per node (the directory does not follow `mld move`)97curl -sI localhost:8830/maps/v1/catalog.json            # 404 until a catalog is published, 200 afterwards98pnpm exec vitest run tests/maps.test.ts99```100
Files main
Menu

Theme