withastro / adapters

Home for Astro's core maintained adapters
47 stars 26 forks source link

Service bindings in the Cloudflare adapter #175

Closed F0rce closed 4 months ago

F0rce commented 4 months ago

Astro Info

Astro                    v4.4.6
Node                     v20.10.0
System                   macOS (x64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/react
                         @astrojs/tailwind

Describe the Bug

Currently the @astrojs/cloudflare adapter does not support Service bindings.

What's the expected result?

Service bindings are a crucial part if you want to call a worker from the server side part of a page if they are hosted on the same domain (and the worker uses a worker route). I already had a bigger conversation with Cloudflare and even had a post on the forum explaining everything (reference). I would really appreciate if the adapter would have the ability to request a worker through a service binding.

I'm willing to submit a pull request for this issue if I'm assisted in some sort of way :)

Thanks a lot, David

Link to Minimal Reproducible Example

https://developers.cloudflare.com/workers/configuration/bindings/about-service-bindings/

Participation

F0rce commented 4 months ago

Just for clarification:

Service bindings work totally fine when deployed to Cloudflare and setup via the Dashboard. This "feature" is more like for development purposes, especially because miniflare can do that.

alexanderniebuhr commented 4 months ago

Thanks for opening the issue. We are happy to get contributions for this. We will hopefully don't need this anymore with the upcoming v10, but for v9 it still would be great to have it added.

F0rce commented 4 months ago

Thanks for the answer @alexanderniebuhr

Is there any way I could assist with implementing it for v9 (I'm already playing around locally) or better said is it already implemented in v10 for me to test out? (or should I try implementing it for both)

If wanted we could also transfer this "ping pong" to discord, that this issue is as clean as it is.

alexanderniebuhr commented 4 months ago

If you would be open for a PR, please feel free to create one. It should be as simple as adding the options to the config and then passing it to the Miniflare instance (I guess).. If you have any question feel free to ping me in Discord.

V10 does not has it implemented yet, and I don't suggest doing it for v10 yet.. If we pull it off that v10 uses workerd natively, it will support everything Miniflare does out-of-the-box :)