Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: integrate edge gateway in api until workers bindings available #53

Conversation

vasco-santos
Copy link
Contributor

@vasco-santos vasco-santos commented Apr 25, 2022

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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 25, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 062dfcb
Status: ✅  Deploy successful!
Preview URL: https://fcdaec08.nftstorage-link.pages.dev

View logs

@vasco-santos vasco-santos force-pushed the fix/integrate-edge-gateway-in-api-until-workers-bindings-available branch 7 times, most recently from 9143d12 to 3e06e41 Compare April 29, 2022 18:38
@vasco-santos vasco-santos force-pushed the fix/integrate-edge-gateway-in-api-until-workers-bindings-available branch from 3e06e41 to 61fd1d1 Compare May 10, 2022 16:06
@vasco-santos vasco-santos marked this pull request as ready for review May 11, 2022 09:18
@vasco-santos vasco-santos force-pushed the fix/integrate-edge-gateway-in-api-until-workers-bindings-available branch 3 times, most recently from 75d9350 to 0887ffb Compare May 11, 2022 12:21
@vasco-santos vasco-santos mentioned this pull request May 11, 2022
32 tasks
@vasco-santos vasco-santos force-pushed the fix/integrate-edge-gateway-in-api-until-workers-bindings-available branch from 0887ffb to 0137a42 Compare May 11, 2022 16:59
@vasco-santos vasco-santos requested a review from alanshaw May 11, 2022 17:34
@vasco-santos vasco-santos force-pushed the fix/integrate-edge-gateway-in-api-until-workers-bindings-available branch from 0137a42 to 062dfcb Compare May 17, 2022 12:07
@vasco-santos vasco-santos merged commit de8d45d into main May 17, 2022
@vasco-santos vasco-santos deleted the fix/integrate-edge-gateway-in-api-until-workers-bindings-available branch May 17, 2022 12:10
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.

2 participants