feat(api): purge Cloudflare CDN before and after OpenAPI spec upload (#704)
* feat(api): purge Cloudflare CDN before and after OpenAPI spec upload Purge api.cdn.clsrio.com edge cache for openapi-latest and the dated spec URL so deploys are not blocked by the 1h Cache-Control TTL on R2 objects. Uses the same CLOUDFLARE_API_TOKEN and CLOUDFLARE_ZONE_ID pattern as embed uploads; skips when credentials are unset. Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com> * fix(api): purge OpenAPI CDN cache only after upload Match the embeds upload pattern: update R2 first, then invalidate edge cache so clients refetch the new spec. Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com> * fix(api): treat Cloudflare purge 2xx as success when body is unparseable Avoid false upload failures when the purge API returns 200 with a non-JSON body. Addresses Greptile review on #704. Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com>
This commit is contained in:
co-authored by
Rotimi Best
Cursor Agent
parent
ec61bfe7d9
commit
efdcfba68d
@@ -33,6 +33,14 @@ CLOUDFLARE_SECRET_ACCESS_KEY=your_secret_key
|
||||
CLOUDFLARE_ACCOUNT_ID=your_account_id
|
||||
```
|
||||
|
||||
Optional — purge Cloudflare CDN cache for `api.cdn.clsrio.com` (after R2 upload):
|
||||
|
||||
```bash
|
||||
CLOUDFLARE_API_TOKEN=your_api_token # Zone → Cache Purge → Purge
|
||||
CLOUDFLARE_ZONE_ID=your_zone_id
|
||||
OPENAPI_SKIP_CDN_PURGE=1 # skip purge when set
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
The script will:
|
||||
@@ -43,6 +51,7 @@ The script will:
|
||||
4. **Upload to R2** (if credentials provided):
|
||||
- `openapi/public-api/openapi-YYYY-MM-DD.json` (dated version)
|
||||
- `openapi/public-api/openapi-latest.json` (latest version)
|
||||
5. **Purge Cloudflare CDN** (if `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ZONE_ID` are set) for both public URLs, after upload
|
||||
|
||||
## GitHub Action Integration
|
||||
|
||||
@@ -63,11 +72,16 @@ The GitHub Action runs on:
|
||||
- `CLOUDFLARE_SECRET_ACCESS_KEY`
|
||||
- `CLOUDFLARE_ACCOUNT_ID`
|
||||
|
||||
2. **Optional secrets** (CDN cache purge for `api.cdn.clsrio.com`):
|
||||
- `CLOUDFLARE_API_TOKEN`
|
||||
- `CLOUDFLARE_ZONE_ID`
|
||||
|
||||
## Features
|
||||
|
||||
- ✅ Automatic OpenAPI spec generation from Hono routes
|
||||
- ✅ Local file generation for development
|
||||
- ✅ Cloudflare R2 upload with versioning
|
||||
- ✅ Optional Cloudflare CDN cache purge (after upload)
|
||||
- ✅ GitHub Action integration
|
||||
- ✅ Environment-specific deployments
|
||||
- ✅ PR previews and artifacts
|
||||
|
||||
Reference in New Issue
Block a user