Support cors proxy #56

Closed
opened 2026-04-23 22:38:30 +00:00 by maxtkc · 0 comments
Owner

Summary

Add a "Use CORS proxy" checkbox (checked by default) to two places: the "Load from URL" modal and the Atlas Search modal in coloring-book (gtfs.zone), and the Feed Configuration card in test-track (viz.rt.gtfs.zone) — covering both the static GTFS URL and all three realtime feed URL inputs. When checked, URLs are prefixed with https://cors.gtfs.zone/ before fetching. A clickable ? link opens the MDN CORS guide in a new tab; a DaisyUI tooltip on that link explains what the proxy does and why it is usually needed.

Relevant Context

coloring-book (~/Documents/coloring-book)

  • src/modules/ui.tsshowFromURLModal() (line 334): renders the "Load from URL" modal body as an HTML string passed to showModal(). The checkbox + help link go here, below the URL input.
  • src/modules/ui.tsloadGTFSFromURL(url) (line 370): calls this.gtfsParser!.parseFromURL(url). URL rewriting happens in the onClick handler of showFromURLModal before calling this method.
  • src/modules/atlas-search.tsshowAtlasSearchModal() (line 103): currently returns string | null. The checkbox goes inside this modal. Return type changes to { url: string; useCors: boolean } | null.
  • Caller of showAtlasSearchModal is in src/modules/ui.ts (line ~120); applies the proxy prefix there before calling loadGTFSFromURL.
  • src/modules/modal-utils.ts: showModal({ title, body, actions, onMount, enterAction, escapeAction }). body is an HTML string; onMount(close) is where DOM listeners are wired.
  • Tooltip pattern (from src/index.html lines 143–145): class="tooltip tooltip-bottom" + data-tip="..." on a wrapper element. The same element can also be the <a> tag or a wrapping <span>.
  • Styling: Tailwind v4 + DaisyUI v5. Use checkbox checkbox-sm, label-text text-sm, btn btn-ghost btn-xs btn-circle.

test-track (~/Documents/test-track)

  • src/index.html lines 80–103: the "Static GTFS" section has <input id="static-gtfs-url" ...> followed by an "or Upload" row. Lines 107–138: the "Realtime Feeds" section has three URL inputs (#rt-vehicles-url, #rt-trip-updates-url, #rt-alerts-url). A single shared checkbox covers all four URLs.
  • src/index.tsloadFeeds() (line 44): reads all URL inputs and constructs feeds. URL rewriting for all four URLs happens here.
  • src/gtfs-static.tsloadFromUrl(url) (line 46): calls fetch(url) directly — no changes needed there.
  • src/gtfs-rt.tsGTFSRealtime constructor (line 13): accepts vehicleUrl, tripUpdatesUrl, alertsUrl as plain strings — rewriting happens before construction in loadFeeds(); no changes needed in gtfs-rt.ts.

Phases

Phase 1 — coloring-book: "Load from URL" modal

Goal: Add a checked-by-default CORS proxy checkbox with a ? help link to the existing URL modal, and route the URL through the proxy when checked.

  • In showFromURLModal() (src/modules/ui.ts line 337), extend the body string with a row below the URL input.
  • In the "Load" action's onClick handler, read the checkbox state and rewrite the URL.
  • Pass effectiveUrl to this.loadGTFSFromURL(effectiveUrl).

Phase 2 — coloring-book: Atlas Search modal

Goal: Add the same checkbox to the Atlas Search modal so feeds selected from the atlas are also proxied when desired.

  • In showAtlasSearchModal() (src/modules/atlas-search.ts line 108), add the same checkbox + ? help link HTML below the search input (same snippet as Phase 1, reuse id="cors-proxy-checkbox").
  • Change the return type from string | null to { url: string; useCors: boolean } | null.
  • Update the selectedUrl variable to be { url: string; useCors: boolean } | null.
  • In onSelect, capture checkbox state.
  • In the caller in src/modules/ui.ts (~line 120), apply proxy prefix.

Phase 3 — test-track: Feed Configuration card

Goal: Add a single CORS proxy checkbox (covering all URL inputs — static and RT) to test-track's feed config card.

  • In src/index.html, add the checkbox row after the divider between the Static GTFS and Realtime Feeds sections (line ~105).
  • Remove the existing RT note on line 136 (Note: RT endpoints must allow viz.rt.gtfs.zone via CORS.) since the proxy handles this now.
  • In src/index.tsloadFeeds() (line 44), read the checkbox once and apply to all URLs via a maybeProxy helper.

Gotchas

  • Proxy URL format: https://cors.gtfs.zone/<original-url> — no URL encoding needed; the proxy reads the path directly.
  • Guard against double-proxying: skip the prefix if the URL already starts with https://cors.gtfs.zone/.
  • A single shared checkbox in test-track covers all four URL inputs (static + 3 RT). The maybeProxy helper keeps the rewriting DRY.
  • DaisyUI v5 tooltip: class="tooltip tooltip-bottom" + data-tip="..." on the same element. Confirmed by usage in src/index.html lines 143–145.
## Summary Add a "Use CORS proxy" checkbox (checked by default) to two places: the "Load from URL" modal and the Atlas Search modal in coloring-book (gtfs.zone), and the Feed Configuration card in test-track (viz.rt.gtfs.zone) — covering both the static GTFS URL and all three realtime feed URL inputs. When checked, URLs are prefixed with `https://cors.gtfs.zone/` before fetching. A clickable `?` link opens the MDN CORS guide in a new tab; a DaisyUI tooltip on that link explains what the proxy does and why it is usually needed. ## Relevant Context ### coloring-book (`~/Documents/coloring-book`) - **`src/modules/ui.ts` → `showFromURLModal()`** (line 334): renders the "Load from URL" modal body as an HTML string passed to `showModal()`. The checkbox + help link go here, below the URL input. - **`src/modules/ui.ts` → `loadGTFSFromURL(url)`** (line 370): calls `this.gtfsParser!.parseFromURL(url)`. URL rewriting happens in the `onClick` handler of `showFromURLModal` before calling this method. - **`src/modules/atlas-search.ts` → `showAtlasSearchModal()`** (line 103): currently returns `string | null`. The checkbox goes inside this modal. Return type changes to `{ url: string; useCors: boolean } | null`. - Caller of `showAtlasSearchModal` is in `src/modules/ui.ts` (line ~120); applies the proxy prefix there before calling `loadGTFSFromURL`. - **`src/modules/modal-utils.ts`**: `showModal({ title, body, actions, onMount, enterAction, escapeAction })`. `body` is an HTML string; `onMount(close)` is where DOM listeners are wired. - **Tooltip pattern** (from `src/index.html` lines 143–145): `class="tooltip tooltip-bottom"` + `data-tip="..."` on a wrapper element. The same element can also be the `<a>` tag or a wrapping `<span>`. - **Styling**: Tailwind v4 + DaisyUI v5. Use `checkbox checkbox-sm`, `label-text text-sm`, `btn btn-ghost btn-xs btn-circle`. ### test-track (`~/Documents/test-track`) - **`src/index.html`** lines 80–103: the "Static GTFS" section has `<input id="static-gtfs-url" ...>` followed by an "or Upload" row. Lines 107–138: the "Realtime Feeds" section has three URL inputs (`#rt-vehicles-url`, `#rt-trip-updates-url`, `#rt-alerts-url`). A single shared checkbox covers all four URLs. - **`src/index.ts` → `loadFeeds()`** (line 44): reads all URL inputs and constructs feeds. URL rewriting for all four URLs happens here. - **`src/gtfs-static.ts` → `loadFromUrl(url)`** (line 46): calls `fetch(url)` directly — no changes needed there. - **`src/gtfs-rt.ts` → `GTFSRealtime` constructor** (line 13): accepts `vehicleUrl`, `tripUpdatesUrl`, `alertsUrl` as plain strings — rewriting happens before construction in `loadFeeds()`; no changes needed in `gtfs-rt.ts`. ## Phases ### Phase 1 — coloring-book: "Load from URL" modal **Goal**: Add a checked-by-default CORS proxy checkbox with a `?` help link to the existing URL modal, and route the URL through the proxy when checked. - [x] In `showFromURLModal()` (`src/modules/ui.ts` line 337), extend the `body` string with a row below the URL input. - [x] In the "Load" action's `onClick` handler, read the checkbox state and rewrite the URL. - [x] Pass `effectiveUrl` to `this.loadGTFSFromURL(effectiveUrl)`. ### Phase 2 — coloring-book: Atlas Search modal **Goal**: Add the same checkbox to the Atlas Search modal so feeds selected from the atlas are also proxied when desired. - [x] In `showAtlasSearchModal()` (`src/modules/atlas-search.ts` line 108), add the same checkbox + `?` help link HTML below the search input (same snippet as Phase 1, reuse `id="cors-proxy-checkbox"`). - [x] Change the return type from `string | null` to `{ url: string; useCors: boolean } | null`. - [x] Update the `selectedUrl` variable to be `{ url: string; useCors: boolean } | null`. - [x] In `onSelect`, capture checkbox state. - [x] In the caller in `src/modules/ui.ts` (~line 120), apply proxy prefix. ### Phase 3 — test-track: Feed Configuration card **Goal**: Add a single CORS proxy checkbox (covering all URL inputs — static and RT) to test-track's feed config card. - [x] In `src/index.html`, add the checkbox row after the divider between the Static GTFS and Realtime Feeds sections (line ~105). - [x] Remove the existing RT note on line 136 (`Note: RT endpoints must allow viz.rt.gtfs.zone via CORS.`) since the proxy handles this now. - [x] In `src/index.ts` → `loadFeeds()` (line 44), read the checkbox once and apply to all URLs via a `maybeProxy` helper. ## Gotchas - Proxy URL format: `https://cors.gtfs.zone/<original-url>` — no URL encoding needed; the proxy reads the path directly. - Guard against double-proxying: skip the prefix if the URL already starts with `https://cors.gtfs.zone/`. - A single shared checkbox in test-track covers all four URL inputs (static + 3 RT). The `maybeProxy` helper keeps the rewriting DRY. - DaisyUI v5 tooltip: `class="tooltip tooltip-bottom"` + `data-tip="..."` on the same element. Confirmed by usage in `src/index.html` lines 143–145.
maxtkc self-assigned this 2026-04-23 22:38:30 +00:00
maxtkc added this to the GTFS Realtime project 2026-04-23 22:38:30 +00:00
maxtkc changed title from Support cors proxy in coloring-book to Support cors proxy 2026-04-23 22:41:18 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
gtfs.zone/deploy-gtfs-rt#56
No description provided.