fix: integrate edge gateway in api until workers bindings available #53
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.
We have two workers now, one for the gateway and one for the API, as they should just be independent services.
As part of
/perma-cache/put/
, a request must be performed to the gateway in order to get the response to be stored in R2. However, two workers cannot HTTP with each other if they are within same CF zone (nftstorage.link).There is a brand new solution for this https://blog.cloudflare.com/service-bindings-ga/ which as of 10th May is now open. However, there is an incompatibility between Service Bindings and R2. When we do a fetch from a Service Binding and put its response in R2 it errors (created a reproduction case and shared with CF a few weeks ago https://github.com/vasco-santos/workers-bindings-r2 but waiting on getting it fixed).
As a way to be able to test this in staging, this PR has a small refactor on gateway code to export relevant function that API can just import and use (of course with its own ENV Vars properly setup...).
This can also be seen as a first step to extract common code of the gateway to a lib. But I avoided much complexity now and It essentially decouples all Durable Objects related code and adds callbacks for it. We will still need to discuss better how to decouple remaining pieces for getting an independent lib extracted.