fix(map): use CORS-enabled R2 URL for PMTiles in Tauri desktop (#1119)

The CF proxy custom domain (maps.worldmonitor.app) doesn't forward R2
CORS headers, so PMTiles fails silently in Tauri where the origin is
https://tauri.localhost. Web works because it's same-origin via CF proxy.

Detect Tauri via __TAURI__ and swap to VITE_PMTILES_URL_PUBLIC (direct
R2 public URL with CORS). Web continues using the CF proxy URL for
edge caching benefits.

Requires adding https://tauri.localhost to R2 CORS allowed origins.
This commit is contained in:
Elie Habib
2026-03-06 13:53:55 +04:00
committed by GitHub
parent 804e4128f6
commit 9a6ae69124
2 changed files with 8 additions and 1 deletions

View File

@@ -174,6 +174,10 @@ VITE_MAP_INTERACTION_MODE=3d
# Leave empty to use free OpenFreeMap tiles. Set to your own PMTiles URL for self-hosted tiles.
# See: https://protomaps.com/docs/pmtiles for how to generate PMTiles files.
VITE_PMTILES_URL=
# Public CORS-enabled URL for the same PMTiles file (used by Tauri desktop app).
# If your VITE_PMTILES_URL is behind a reverse proxy without CORS, set this to the
# direct R2/S3 public URL. The desktop app uses this URL; the web app uses VITE_PMTILES_URL.
VITE_PMTILES_URL_PUBLIC=
# ------ Desktop Cloud Fallback (Vercel) ------

View File

@@ -3,7 +3,10 @@ import maplibregl from 'maplibre-gl';
import { layers, namedFlavor } from '@protomaps/basemaps';
import type { StyleSpecification } from 'maplibre-gl';
const R2_BASE = import.meta.env.VITE_PMTILES_URL ?? '';
const R2_PROXY = import.meta.env.VITE_PMTILES_URL ?? '';
const R2_PUBLIC = import.meta.env.VITE_PMTILES_URL_PUBLIC ?? '';
const isTauri = typeof window !== 'undefined' && '__TAURI__' in window;
const R2_BASE = isTauri && R2_PUBLIC ? R2_PUBLIC : R2_PROXY;
const hasTilesUrl = !!R2_BASE;