fix: correct data loading for GitHub Pages#7
Conversation
- use relative paths for data files to work with base URL - improve error handling for fetch requests - add documentation for deployment to GitHub Pages - explain how to configure base path for static JSON and assets - add troubleshooting steps for common JSON parse error
|
Caution Review failedThe pull request is closed. WalkthroughAdded deployment guidance for GitHub Pages with BASE_PATH/BASE_URL usage, switched index.html module script to a relative path, and refactored data loading in api.ts to use a centralized BASE_URL-driven fetchJson helper with enhanced error handling and URL construction for JSON assets and cutout URLs. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User Browser
participant A as App (Dashboard)
participant L as Data Loader (fetchJson)
participant S as Static Host (GitHub Pages)
Note over A,L: BASE_URL taken from import.meta.env.BASE_URL
U->>A: Open dashboard
A->>L: loadDatabase()
activate L
L->>L: buildDataUrl("database.json")
L->>S: GET <BASE_URL>data/database.json (no-cache)
alt 200 OK JSON
S-->>L: JSON body
L-->>A: Parsed DataRecord[]
else Error/HTML/404
S-->>L: Error or HTML body
L-->>A: Reject with status, URL, snippet
end
deactivate L
A->>L: loadCutouts()
L->>S: GET <BASE_URL>data/cutouts.json
S-->>L: JSON or error
L-->>A: Parsed CutoutRecord[] or error
Note over A: Other loaders (dictionary, consolidated) follow same flow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary by CodeRabbit
• Documentation
• Added detailed GitHub Pages deployment guide, including base path setup, build command example, verification steps, and notes about data file placement and trailing slash requirements.
• Bug Fixes
• Fixed script and data path resolution for subpath hosting to prevent 404s and JSON parse errors.
• Refactor
• Centralized data loading with environment-driven base URL, consistent relative paths, no-cache fetches, and clearer error reporting for failed requests or invalid JSON.