feat: integrate Metrolinx Open Data API for live service alerts#18
Open
faizm10 wants to merge 12 commits into
Open
feat: integrate Metrolinx Open Data API for live service alerts#18faizm10 wants to merge 12 commits into
faizm10 wants to merge 12 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Replaces the gotransit.com HTML scraper with the official Metrolinx API (key: env METROLINX_API_KEY) for service alerts, with the scraper kept as a graceful fallback when the API is unavailable. - lib/metrolinx.ts: typed API client for the Metrolinx Open Data API at api.openmetrolinx.com — covers service alerts, stop departures, next service, and stop details. All requests server-side only. - lib/serviceUpdates.ts: fetchServiceUpdates() now tries the real API first; falls back to gotransit.com scrape if METROLINX_API_KEY is missing or the API errors - app/api/metrolinx/departures/route.ts: proxy endpoint for live stop departures (?stop=UN&mode=departures|next), cached 60 s - app/api/metrolinx/alerts/route.ts: raw alerts proxy, cached 5 min Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- serviceUpdates.ts: adds "metrolinx-api" source type so the UI can
distinguish real API data from the HTML scraper fallback
- service-updates/page.tsx: source-aware badge ("Live — Metrolinx API"
vs "Scraped — gotransit.com"), active alert stats row (total / delays /
cancellations), and footer attribution switches between Metrolinx API
docs and gotransit.com based on actual data source
- AlertCard.tsx: "use client" expand/collapse for long alert bodies
(real API responses are often verbose), per-severity card border tint,
whitespace-pre-line to preserve line breaks in API body text
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
client/lib/metrolinx.ts— a typed API client for the Metrolinx Open Data API (service alerts, stop departures, stop details), keeping the API key server-sideGET /api/metrolinx/alertsandGET /api/metrolinx/departures?stop=<code>&mode=departures|nextfetchServiceUpdatesto use the Metrolinx API as the primary source (with the existing gotransit.com HTML scrape as automatic fallback) — no downtime if the key is missingSourceBadgeto the Service Updates page showing "Live — Metrolinx API" vs "Scraped — gotransit.com" vs "Source unavailable"AlertCardto severity-coloured borders and expandable "Read more / Show less" body text for long alertsTest plan
METROLINX_API_KEYin.env.localand verify the Service Updates page shows the green "Live — Metrolinx API" badgeGET /api/metrolinx/alertsdirectly and confirm JSON is returned with cache headersGET /api/metrolinx/departures?stop=UNand confirm departure data comes back🤖 Generated with Claude Code