SPB Git

Repository Public

map-distribution.md 7.0 KB

# Map distribution (/maps/v1)

The site serves the signed region packages of ORIX Maps the same way it serves the model library of ORIX Astra (/astra/models/v1): plain files, no account, no API key, no page. The contract is docs/CATALOG_API.md of the ORIX Maps repository (section 2, "Server requirements"); the route is src/app/maps/v1/[...path]/route.ts, the tests are tests/maps.test.ts.

The public page /maps (/fr/maps, src/app/[locale]/maps/page.tsx) lists the published regions for visitors. It reads catalog.json and regions/<id>.json from the same directory through src/lib/maps.ts (tests: tests/maps-library.test.ts), offers no link to a package, and shows an empty state when no catalogue is published.

# Resources

GET / HEAD File under the distribution root Content-Type Cache-Control
/maps/v1/catalog.json catalog.json application/json public, max-age=300
/maps/v1/regions/<id>.json regions/<id>.json application/json public, max-age=300
/maps/v1/regions/<id>/versions.json regions/<id>/versions.json application/json public, max-age=300
/maps/v1/files/<id>/<dataVersion>/<id>-<dataVersion>.orixmap same path application/vnd.orix.map public, max-age=31536000, immutable, no-transform

<id> is [a-z0-9-]{1,64}; <dataVersion> is a dotted decimal version (up to eight groups of digits). Every other path answers 404, including pins.json (publisher state) and any other file placed in the directory.

# Distribution directory

ORIX_MAPS_DIR (default ~/apps-data/orix-maps) + /v1, outside the deployment and outside git. It is written by orix-package publish / orix-package catalog (ORIX Maps repository), which replace each file by a rename and write catalog.json last; the route only reads.

text
~/apps-data/orix-maps/v1/catalog.json
~/apps-data/orix-maps/v1/regions/ca-qc-montreal.json
~/apps-data/orix-maps/v1/regions/ca-qc-montreal/versions.json
~/apps-data/orix-maps/v1/files/ca-qc-montreal/2026.11.24/ca-qc-montreal-2026.11.24.orixmap
~/apps-data/orix-maps/v1/pins.json            (never served)

An empty or missing directory is a valid state: everything answers 404. Publishing needs no restart: documents are read again when their modification time or size changes. Never overwrite a published package (its URL is cached as immutable); new data is a new dataVersion. Packages signed with a development key must not be placed here.

# Behaviour

  • Listing rule. A package is served only when the current catalog.json (regions[].latest) or the region's versions.json (versions[]) lists it with that exact path, a downloadSize and a 64-digit lowercase sha256, and the size on disk equals downloadSize. Otherwise 404. Removing a version from both documents withdraws it.
  • ETag. Always strong: "<sha256 hex>". For a package it is the listed sha256 (packages are never hashed by the server: the bytes are only checked by size, the application verifies digest and signature). For a JSON document it is the SHA-256 of the file, computed once per (mtime, size).
  • If-None-Match → 304 (list of tags, *, weak comparison), evaluated before Range.
  • Range (packages, GET only): bytes=a-b, bytes=a- and the suffix form bytes=-n → 206 with Content-Range and Content-Length; a last byte past the end is clamped. A range starting at or after the end, or bytes=-0 → 416 with Content-Range: bytes */<size>. A header that asks for several ranges, uses another unit or is malformed is ignored and the whole file is sent with 200 (RFC 9110 §14.2 allows a server to ignore Range). HEAD ignores Range and reports the full length.
  • If-Range: the range is honoured only when the value is exactly the current strong ETag. Any other value (another tag, a weak tag, a date) → 200 with the whole file, even when the range itself would be unsatisfiable.
  • Headers on every answer: X-Content-Type-Options: nosniff, X-Robots-Tag: noindex, Access-Control-Allow-Origin: *; Accept-Ranges: bytes on packages. Never Set-Cookie, never Content-Encoding (the site does not compress; no-transform asks the gateway not to compress a package either).
  • Content-Length: set by the route, not on the wire. The handler sets Content-Length on every 200 and 206 (the tests check it), but Next.js 16.4 removes Content-Length from every route-handler response (FORBIDDEN_HEADERS in next/dist/server/send-response.js) and sends the body with chunked transfer encoding; a HEAD answer carries no length either. The same holds for /astra/models/v1. Clients must take the size from the catalog (downloadSize) or from Content-Range (bytes a-b/<total>, which is delivered); a truncated transfer is still detected by the HTTP framing. Sending the header would need a response written outside the App Router (a Pages API route or the gateway).
  • Safety. The URL must match one of the four shapes before the file system is touched; the resolved path (realpath) must stay under the resolved distribution root, so neither .. nor a symbolic link can lead outside. A JSON document larger than 8 MiB (the client's own limit) is not served.
  • Rate limit. 300 requests per 60 seconds and per client address (scope orix-maps of lib/security/ratelimit), then 429 with Retry-After: <seconds until the window ends>. A download costs one request per attempt or resume.
  • Errors. An unexpected failure answers a bare 500 and logs nothing.

Requests without a file extension that match none of the shapes (/maps/v1/regions/x) never reach the route: the locale proxy rewrites them to the site's own 404 page (status 404, HTML), like any unknown page.

# What is recorded about a download

  • The route: nothing. No log line, no counter, no database row, no file. (The anonymous download counters of /download do not apply here.)
  • The Next.js process (orix-web under PM2, logs in ~/.pm2/logs/orix-web-{out,error}.log): next start writes no access log. The output log holds start-up lines only; the error log holds stack traces of unexpected server errors, without address or headers.
  • In memory only: the rate limiter keeps, per client address, a request count and the end of the current 60-second window (orix-maps:<address>). It is never written to disk, is gone at every restart of orix-web, and expired entries are dropped when the table is pruned.
  • The gateway (Caddy on the public server, in front of this node) terminates TLS and sees the address, the time, the URL and the size of every request. Whether and how long it logs them is its own configuration, outside this repository.

# Operations

bash
mkdir -p ~/apps-data/orix-maps/v1                       # once per node (the directory does not follow `mld move`)
curl -sI localhost:8830/maps/v1/catalog.json            # 404 until a catalog is published, 200 afterwards
pnpm exec vitest run tests/maps.test.ts
Files main
Menu

Theme