james-elicx / cf-bindings-proxy

Experimental proxy for interfacing with bindings in projects targeting Cloudflare Pages
MIT License
94 stars 4 forks source link

`wrangler` supports binds to CF service, doesn't it? #50

Closed mostrecent closed 8 months ago

mostrecent commented 8 months ago

Guess I must miss something but from what I read, wrangler does bind CF services locally:

Local development is supported for Service bindings. For each Worker, open a terminal and use wrangler dev in the relevant directory or use the SCRIPT option to specify the relevant Worker’s entrypoint. [1]

I assume the challenging part is to get this working with your framework (I use SvelteKit). So, I wonder if I should enter this rabbit-hole or just keep using non-CF services which makes setting up the local dev experience easy (usually).

[1] https://developers.cloudflare.com/workers/configuration/bindings/about-service-bindings/#local-development

james-elicx commented 8 months ago

The purpose of this tooling is to get access to bindings in an environment where it is not normally possible to, i.e. when not using wrangler or when the framework doesn't have built-in support for dev mode.

mostrecent commented 8 months ago

Ah ok and this makes sense but then again, why wouldn't you want to use wrangler when using Workers?

james-elicx commented 8 months ago

Because you may wish to use a framework's dev server. For instance, if you want HMR when building a Next.js site, you would need to use next dev. I made this tool originally so that I could have bindings in Next.js' dev server. We now have first-class support for bindings in next-on-pages so this is no longer needed for Next.js, but that was the idea behind when it'd be used originally.

mostrecent commented 8 months ago

Ok, makes sense, we had the same situation with SvelteKit, now we have access and can run SvelteKit wrapped in wrangler but accessing those binds isn't really straight-forward, e.g. right now I wonder how to access a Neon DB connected via Cloudflare newest product Hyperdrive. Not sure if I gonna enter that rabbit-hole...