fix(forex): fetch BSP exchange rates directly from the browser - #752
Open
irishmicoletcando wants to merge 1 commit into
Open
irishmicoletcando wants to merge 1 commit into
irishmicoletcando wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Foreign Exchange Rates page (
/data/forex) and the homepage forex ticker were failing withAPI request failed with status 404. The frontend fetched fromhttps://api.bettergov.ph/forex, a Cloudflare Worker that reads exchange rates from a KV store. That KV store was never being populated: the scheduled Worker that fills it fetches BSP directly, and BSP's WAF returns 403 Forbidden to the Cloudflare Workers runtime — so the key stayed empty and every read returned 404.This PR removes the KV/Worker dependency for forex entirely and fetches the official BSP exchange-rate list directly from the browser. BSP serves
Access-Control-Allow-Origin: *and its WAF allows real browser clients (only datacenter/worker runtimes are blocked), so no proxy, backend, KV store, or scheduled job is required.Before / After
Root cause
https://api.bettergov.ph/forex(KV-only Worker endpoint).bsp_exchange_ratesfrom KV; the key is empty, so it returns 404.curland real browsers get 200 for the identical request).Changes
src/lib/forex.ts— fetch the BSP OData exchange-rate endpoint directly, request JSON explicitly (BSP defaults to XML), and mapvalue[]→ForexRate. Rows BSP reports asN/A(e.g. KWD) parse toNaN, so they are filtered out rather than rendered as a blank rate.src/lib/api.ts—fetchWithCachenow accepts an optionalRequestInitso the forex call can sendAccept: application/json. Signature is backward-compatible; existing callers are unaffected.No changes to the
ForexRateshape or the 1-hour client cache, soTicker,InfoWidgets, and the forex page work unchanged.Test plan
/data/forexrenders the currency list, rate card, and converter with live BSP data (USD ₱62.6700; ₱1000 → $15.96).N/Acurrencies (e.g. KWD) are omitted — no blank rows.tsc --noEmitpasses; no new console errors on load.Notes
pr-assets/forex-direct-bspbranch on the fork, so they are not part of this PR's diff.