Skip to content

Modernize the members map and fix blocked map tiles - #1

Merged
dbader merged 1 commit into
masterfrom
claude/project-thread-pm5duv
Dec 3, 2026
Merged

dbader merged 1 commit into
masterfrom
claude/project-thread-pm5duv

Conversation

@dbader

@dbader dbader commented Dec 3, 2026

Copy link
Copy Markdown
Member

Requested by Dan · project thread

Why

Map tiles on https://members-map.realpython.com show OpenStreetMap's "403 Access blocked" image. folium 0.7 rendered the map into an iframe whose src is a base64 data: URL. That document has no origin, so the browser sends tile requests without a Referer, which the OSM tile usage policy now enforces. The app also ran Python 3.7 on heroku-20, which can no longer build.

What

  • The map is drawn with Leaflet 1.9.4 (vendored) directly in the page, using https://tile.openstreetmap.org/{z}/{x}/{y}.png and Referrer-Policy: strict-origin-when-cross-origin. Pins are clustered and nicknames appear as hover tooltips (1,067 permanent labels were unreadable). Nicknames are inserted as text, not HTML.
  • Python 3.14 with uv (pyproject.toml, uv.lock, .python-version) for the heroku-26 stack. Flask 3, psycopg 3, geopy 2, gunicorn. folium and numpy are gone.
  • members_map/ package with an app factory, small DB layer, and flask --app members_map init-db (CREATE TABLE IF NOT EXISTS, run in the Heroku release phase, a no-op on the existing table).
  • Form validation (lengths, empty input), and a clear message when Nominatim is down instead of "location not found".
  • /export/json used to hand all data to anyone. It now needs EXPORT_PASSWORD via HTTP basic auth and returns 404 when the variable is unset. The JSON shape is unchanged.
  • Removed: /hello, /map (rendered an empty map), Windows Procfile, dead DB helpers.
  • 14 pytest tests against Postgres, ruff, GitHub Actions CI.

Testing

  • uv run pytest: 14 passed. ruff check and ruff format --check are clean.
  • Ran it under gunicorn with 1,067 seeded pins and loaded it in headless Chromium. All 18 tile requests carried a Referer and returned 200, with no page errors, on both desktop and mobile widths.
  • Not verified here: live Nominatim geocoding, because the sandbox proxy blocks it. The geopy call is unchanged apart from a descriptive User-Agent and a 5s timeout.

Deploy notes

  • The table and data stay as they are. No migration is needed.
  • SECRET_KEY should already be set. If it's missing, the app falls back to a random per-process key.
  • Set EXPORT_PASSWORD only if the export is still needed.

Generated by Claude Code

OpenStreetMap blocks tile requests without a Referer. folium 0.7 rendered
the map into a data: URL iframe, which has no origin, so tiles were
refused. The map is now drawn with Leaflet directly in the page, using
the current https://tile.openstreetmap.org URL and a Referrer-Policy
that sends our origin.

- Python 3.14 with uv (pyproject.toml, uv.lock, .python-version) for the
  heroku-26 stack; Flask 3, psycopg 3, geopy 2, gunicorn
- members_map package with an app factory, typed DB helpers and an
  init-db command run in the Heroku release phase
- Marker clustering, nicknames as hover tooltips, responsive layout
- Input validation and a clear message when geocoding is unavailable
- /export/json requires EXPORT_PASSWORD (basic auth), 404 when unset
- pytest suite against Postgres, ruff, GitHub Actions CI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WLRZ1bCeX4qyg1QpD6AQFG
@dbader dbader self-assigned this Dec 3, 2026
@dbader
dbader merged commit 22129f0 into master Dec 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants