fix(map): drop the retired OpenStreetMap tile subdomains (#1733)

The a/b/c shards stopped being necessary in 2022 and d has since lost its
DNS record. The map never asked for d — Leaflet defaults to abc — but the
offline prefetcher rotated over a to d, which is where the failing requests
came from, and it cached most tiles under a host the map never requests.

Presets and the prefetcher use the apex host now. A URL already saved in
user_settings is rewritten where it is read and written back, so existing
instances heal without a migration touching what someone typed themselves.

The CSP only allowed https://*.tile.openstreetmap.org, and a wildcard host
never matches the apex domain, so the prefetch fetch would have been blocked.
The service worker rule had the same gap and would have stopped filling the
tile cache.
This commit is contained in:
Maurice
2026-07-29 14:37:24 +02:00
committed by Maurice
parent f013c4964c
commit 9ecca404c5
18 changed files with 330 additions and 33 deletions
+58
View File
@@ -0,0 +1,58 @@
import { describe, it, expect } from 'vitest'
import { normalizeTileUrl } from './tileUrl'
describe('normalizeTileUrl', () => {
it('drops the {s} placeholder from an OSM template', () => {
expect(normalizeTileUrl('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'))
.toBe('https://tile.openstreetmap.org/{z}/{x}/{y}.png')
})
it('rewrites a hard-coded shard host', () => {
for (const shard of ['a', 'b', 'c', 'd']) {
expect(normalizeTileUrl(`https://${shard}.tile.openstreetmap.org/{z}/{x}/{y}.png`))
.toBe('https://tile.openstreetmap.org/{z}/{x}/{y}.png')
}
})
it('rewrites a protocol-relative template', () => {
// Older templates were often stored without a scheme so they'd follow the
// page. Those reach the network just like the https ones, so the shard
// rewrite has to see them too.
expect(normalizeTileUrl('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'))
.toBe('//tile.openstreetmap.org/{z}/{x}/{y}.png')
expect(normalizeTileUrl('//d.tile.openstreetmap.org/{z}/{x}/{y}.png'))
.toBe('//tile.openstreetmap.org/{z}/{x}/{y}.png')
})
it('keeps http and an explicit port', () => {
expect(normalizeTileUrl('http://{s}.tile.openstreetmap.org:8080/{z}/{x}/{y}.png'))
.toBe('http://tile.openstreetmap.org:8080/{z}/{x}/{y}.png')
})
it('leaves the already-correct host alone', () => {
const url = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
expect(normalizeTileUrl(url)).toBe(url)
})
it('leaves other providers untouched', () => {
const carto = 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png'
expect(normalizeTileUrl(carto)).toBe(carto)
const osmDe = 'https://tile.openstreetmap.de/{z}/{x}/{y}.png'
expect(normalizeTileUrl(osmDe)).toBe(osmDe)
})
it('does not touch a look-alike host', () => {
// Only the {s} placeholder and single shard letters are rewritten — a
// self-hosted mirror keeps its own hostname.
const mirror = 'https://mirror.tile.openstreetmap.org.example.com/{z}/{x}/{y}.png'
expect(normalizeTileUrl(mirror)).toBe(mirror)
const proxy = 'https://tiles.example.com/https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
expect(normalizeTileUrl(proxy)).toBe(proxy)
})
it('passes an empty template through', () => {
expect(normalizeTileUrl('')).toBe('')
})
})
+24
View File
@@ -0,0 +1,24 @@
/**
* OpenStreetMap has not needed the a/b/c.tile.openstreetmap.org subdomains
* since 2022 — tile.openstreetmap.org serves the whole grid on its own — and
* d.tile.openstreetmap.org has meanwhile lost its DNS record entirely. A
* template that still carries the `{s}` placeholder therefore depends on which
* letters the renderer substitutes: everything that lands on `d` fails with
* ERR_NAME_NOT_RESOLVED, which is console noise plus holes in the offline tile
* cache (#1733).
*
* The presets ship the single-host form now, but a template the user (or an
* admin default) saved earlier is still in the database. Rewriting it on read
* fixes those instances without a migration; the settings store rewrites it on
* save as well, so a legacy URL typed by hand converges on the same host
* instead of coming back on the next load. Other providers are left untouched.
*/
/** `{s}.` or a bare shard letter in front of tile.openstreetmap.org. */
const OSM_SHARD = /^((?:https?:)?\/\/)(?:\{s\}|[a-d])\.tile\.openstreetmap\.org(?=[/:]|$)/i
/** Collapse a sharded OSM tile template onto the single supported host. */
export function normalizeTileUrl(url: string): string {
if (!url) return url
return url.replace(OSM_SHARD, '$1tile.openstreetmap.org')
}