mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
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:
@@ -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) ------
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user