Add backend /api/map-tiles endpoint to cache MapTiler map tiles

  • Concurrency Control: Avoids multiple simultaneous fetches of the same tile by tracking inflight promises keyed by tile coordinates.
  • Cache Validation: Properly implements HTTP conditional GET semantics: uses both ETag and Last-Modified validation through client headers If-None-Match and If-Modified-Since.
  • Graceful Cache Expiration: Deletes expired cache files asynchronously without blocking requests.
  • Atomic Writes: Writes incoming tile data to temporary files before renaming atomically to ensure cache coherence.
  • Efficient Stream Handling: Uses promisified stream.pipeline with proper error and client disconnect handling.
  • Detailed Input Validation: Uses regex to guard against path traversal and malformed URL parameters.
  • Error Handling: Differentiates client disconnects from fatal errors to reduce noisy error logs.
  • Consistent Async FS Methods: Uses fs.promises exclusively for non-blocking file system operations.

Summary by CodeRabbit

  • New Features

    • Local caching and serving of map tiles for faster, more reliable maps with HiDPI (@2x) support and freshness checks (304/ETag).
  • Refactor

    • Map components now use a centralized tile provider, unifying tile behavior across the app and removing inline provider setup.
  • Chores

    • Added an HTTP client dependency and updated source control to ignore the persistent tile-cache directory.
Edited by CodeRabbit

Merge request reports

Loading