Skip to content

fix: resolve /forex 404 by adding browser headers and KV fallback fetch - #751

Closed
irishmicoletcando wants to merge 1 commit into
bettergovph:mainfrom
irishmicoletcando:fix/forex-404-kv-fallback
Closed

irishmicoletcando wants to merge 1 commit into
bettergovph:mainfrom
irishmicoletcando:fix/forex-404-kv-fallback

Conversation

@irishmicoletcando

Copy link
Copy Markdown

Summary

  • BSP's WAF was rejecting the Worker-originated scrape with 403, so FOREX_KV never got populated and /forex always returned 404.
  • Add browser-like User-Agent/Referer headers to the BSP fetch in functions/api/forex.ts so the upstream request succeeds.
  • functions/forex.ts now falls back to fetching fresh data directly (and repopulating KV) on a cache miss, instead of hard-404ing the client.

Test plan

  • npx tsc --noEmit -p functions/tsconfig.json passes
  • Verify /forex and /api/forex return live data once deployed (BSP headers depend on network conditions in production)

BSP's WAF was rejecting the Worker-originated scrape (403), leaving the
FOREX_KV cache empty so /forex always 404'd. Add browser-like User-Agent/
Referer headers to the BSP fetch, and have /forex fall back to fetching
fresh data directly (and repopulating KV) instead of hard-404ing on a
cache miss.
@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
bettergov Ready Ready Preview Sep 21, 2026 11:23am UTC

@irishmicoletcando

Copy link
Copy Markdown
Author

Closing in favor of a different approach — testing showed the BSP block is not header-based; it's Cloudflare Workers' fetch client itself being blocked (reproduced locally with zero custom headers still returning 403, vs 200 from plain curl on the same machine). No header change can fix that. Redesigning to scrape BSP from a GitHub Actions cron job instead, writing directly to the Cloudflare KV store via the Cloudflare API, bypassing the Workers runtime entirely. New PR incoming.

This branch was successfully deployed

1 active deployment
Preview aab2973c Deployed Sep 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant