2.7 KiB
Handoff: Fix CORS for CRDC Arrests API Demo App
Current Status
The demo app at https://pages.civilytics.org/crdc-demo/ loads HTML correctly but shows a blank white screen because browser-based fetch requests to the CRDC API are blocked by CORS (the API doesn't send Access-Control-Allow-Origin headers).
What's Done
- ✅ App code: React + Vite app fully built with 6 charts, Civilytics visual identity, loading animation, district search — all committed and building cleanly
- ✅ Git Pages deployment: Gitea Actions workflow (
.gitea/workflows/pages.yml) successfully buildsdist/and deploys to apagesbranch onCivilytics/crdc-demorepo at gitea.civilytics.org - ✅ CORS proxy code added:
- Updated
src/hooks/useApi.js,LoadingAnimation.jsx,ChartPanel.jsxwithVITE_PROXY_URLsupport (routes through a query-param-based proxy) - Added
proxy.php— simple PHP CORS proxy for git-pages hosts that support PHP - Updated Dockerfile nginx.conf to include
/api/v1/reverse proxy with CORS headers
- Updated
What Needs to Be Done Next
Option A: Fix at the API source (recommended, cleanest)
The CRDC API is a Plumber/R service deployed behind Cloudflare. The code change has already been made in crdc-arrests/api/plumber.R — added CORS headers (Access-Control-Allow-Origin: *) to the existing cacheHeaders filter and OPTIONS preflight handling.
Action needed: Deploy this updated plumber.R to the running API server so it takes effect at https://crdc-api.civilytics.org/. The change is in /home/jared/Nextcloud/Civilytics/Code/Civilytics/crdc-arrests/api/plumber.R (lines 56-78).
Option B: Fix on the git-pages server
If you can't restart the API, configure the nginx serving pages.civilytics.org to add CORS headers when proxying requests to crdc-api.civilytics.org. Or deploy proxy.php and set VITE_PROXY_URL=/crdc-demo/proxy.php at build time.
Key Files
- API fix:
/home/jared/Nextcloud/Civilytics/Code/Civilytics/crdc-arrests/api/plumber.R(CORS headers added to cacheHeaders filter) - App code:
/home/jared/Nextcloud/Civilytics/Code/Civilytics/crdc-demo/src/— fully built, deployed to pages branch - Proxy fallback:
proxy.php, nginx.conf with reverse proxy config
Verification Steps After Fix
- Visit https://pages.civilytics.org/crdc-demo/
- Select a state → search for "Denver" → should see district results
- Click a district → loading animation runs, then 6 charts appear
- Check browser dev tools → no CORS errors in console
Git Status
crdc-arrestsrepo: plumber.R modified (CORS headers added), not yet committed/pushed to API deploymentcrdc-demorepo: All fixes pushed and deployed via Gitea Actions, awaiting CORS resolution at API or server level