feat: make the API Worker reachable only from the web Worker via a service binding - #110
Merged
Conversation
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
api.tankalizer.jpround-trip with a Cloudflare service binding, so the frontend calls the API Worker directly inside the Workers runtime.user_id.Changes
Service binding plumbing
frontend/wrangler.jsonc: addservicesbindingAPI→tankalizer-apifrontend/src/lib/backendFetch.ts(new): resolves the binding viagetCloudflareContext()and dispatches requests throughenv.API.fetch()(the URL host is a dummy label; routing is done by the binding). Falls back to a plainfetch(BACKEND_URL + path)when no binding is available, so localnext dev/ docker-compose keep workingCall-site migration
jwtcallback (src/auth/config.ts) now callbackendFetch('/v2/...')instead of building URLs fromprocess.env.BACKEND_URL; request methods, bodies, and headers are unchangedLocking down the API Worker
backend/wrangler.jsonc:workers_dev: falseandpreview_urls: false(theapi.tankalizer.jpcustom domain was removed via the dashboard)Notes
tankalizer.jp(web Worker) → service binding → API Worker → D1/S3. No DNS, TLS, or public hop between the two Workerswrangler devprocesses (binding[connected], SSR post page renders data through the binding) and in production:api.tankalizer.jpnow returns 530 while the site serves normallyBACKEND_URLremains only as the fallback for non-Workers dev environments