cloudflare / workers-sdk

โ›…๏ธ Home to Wrangler, the CLI for Cloudflare Workersยฎ
https://developers.cloudflare.com/workers/
Apache License 2.0
2.75k stars 736 forks source link

Cloudflare bindings aren't available with the `--proxy` flag in `wrangler pages dev` #3616

Closed tom-huntington closed 7 months ago

tom-huntington commented 1 year ago

With npm create cloudflare@latest in astro and svelte the npm run dev command doesn't have cloudlfare bindings available. However, it remix it does. It seems the difference is that remix is not using the --proxy flag

// package.json
    "dev": "remix dev --no-restart -c \"npm run start\"",
    "start": "wrangler pages dev --compatibility-date=2023-06-21 ./public",

while astro wrangler pages dev --compatibility-date=2023-07-15 --proxy 3000 -- astro dev and svelte wrangler pages dev --compatibility-date=2023-07-15 --proxy 5173 -- npm run dev are using --proxy.

You can now get around this with https://github.com/james-elicx/cf-bindings-proxy

Anyway, this just tripped me up so I though I'd share

mrbbot commented 1 year ago

Hey! ๐Ÿ‘‹ Apologies for the delayed response here. This is something we're actively looking at improving. @dario-piotrowicz is currently working on something for Next.js, but we're exploring ideas for other frameworks too. ๐Ÿ‘

dario-piotrowicz commented 1 year ago

Yeah this is some problem we're very aware of and we're exploring ideas on how to improve this. ๐Ÿ‘

PS: Unfortunately what I am doing for our Next.js adaptor is very Next specific so it's a bit unlikely that anything from there can be reused for other frameworks ๐Ÿ˜“

gerhardcit commented 1 year ago

For what it's worth, this is a major stumbling block preventing us from moving a lot of applications to cloudflare. Not being able to dev with bindings is a showstopper.

tom-huntington commented 1 year ago

@gerhardcit

You can now get around this with https://github.com/james-elicx/cf-bindings-proxy

gerhardcit commented 1 year ago

Thx. Initial testing seems that this is working well.

https://github.com/james-elicx/cf-bindings-proxy/issues/43

dario-piotrowicz commented 7 months ago

Hi all ๐Ÿ‘‹

I'm closing the issue as I believe it to be outdated and that the current situation with full stack frameworks and bindings is much better than it was when this issue was opened.

We've implemented the getPlatformProxy utility that frameworks are also taking advantage of in order to provide access to bindings in their dev servers.

For example, among others, that is used in Remix, SvelteKit and Astro.

We're also exploring the possibility to have full stack frameworks run their dev code inside our runtime (providing a very faithful representation of what the actual production application will work like) via the Vite Environment API proposal ๐Ÿคž

I hope this works for you @tom-huntington, if not please feel free to reopen this issue ๐Ÿ™‚๐Ÿ™