galaxyproject / galaxyproject/brc-analytics
CloudFront eating API error responses
- Dominant language
- TypeScript
- Stars
- 7
- Forks
- 11
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 15
Description
We proxy `/api/v1/*` through the main CloudFront distribution to `platform-beta.brc-analytics.org` as a convenience (same domain, no CORS). The backend is already reachable on its own domain — the CloudFront behavior just makes things tidier.
Problem: CloudFront has Custom Error Responses for 403 and 404 to handle SPA routing for the static frontend. These are distribution-level settings, so they apply to ALL behaviors including the API proxy. When the API returns a proper `404 application/json`, CloudFront replaces it with the Next.js HTML error page.
Direct to backend — correct:
```
HTTP/2 404
content-type: application/json
{"detail":"Assembly GCA_030573285.100000 not found"}
```
Through CloudFront — broken:
```
HTTP/2 404
content-type: text/html
...(Next.js error page)...
```
200s pass through fine, only error codes get eaten.
The 403 error response exists because S3 with OAC returns 403 for missing objects, which is what makes SPA routing work. The 404 rule is redundant for S3 but catches API responses we don't want intercepted.
## Options
1. **Delete the 404 Custom Error Response** — S3+OAC never returns 404 anyway, so this rule only hits API responses. Simplest fix.
2. **Drop the CloudFront proxy, use the backend domain directly** — The backend already has its own domain. We only added the `/api/v1/*` behavior for same-origin convenience. Could just point clients at the backend directly and remove the behavior.
3. **CloudFront Function for SPA routing instead of Custom Error Responses** — Remove all error responses, use a viewer-request function to rewrite paths for the static site. Most correct long-term but needs testing.
(reported by @d-callan -- thank you!)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.