Provide local bindings for Cloudflare runtime features in development
Describe the feature
Currently, it is not possible to use Cloudflare runtime-specific feature bindings (like KV, DO, R2, D1, ...) in development. I thought that was a fundamental limitation of the way how Wrangler works. However, I found that the Astro Cloudflare adaptor provides local bindings, using Miniflare in development. It'll be a huge productivity boost on apps that utilize Cloudflare runtime-specific features since it'll allow us to keep iterating on the dev server, rather than building the production bundle per every file saves.
Additional information
- [ ] Would you be willing to help implement this feature?
This can move forward with Wrangler's new getBindingsProxy or their just-released getPlatformProxy that provides cf, ctx, and caches as well as the bindings. That way we can use Nitro's dev server with its HMR and no longer have to do the intermediary build using Wrangler's command and watch_dir options.
I can have a look at it if none of the maintainers would like to do so themselves.
Here is a Nitro module we made in collaboration with CF team: https://github.com/pi0/nitro-cloudflare-dev/tree/main that leverages this API (sorry for lack of docs)
In the close feature it will be even better by being able to directly use Wrangler as Dev server rntime.
Amazing news @pi0! Can't wait to make use of it!
i need it, too.
for, now i use:
package.json
scripts: {
...
"dev:wrangler": "NITRO_PRESET=cloudflare_module wrangler dev .output/server/index.mjs --env development --site .output/public --port 8101",
"proxy": "local-ssl-proxy --key ../127.0.0.1+7-key.pem --cert ../127.0.0.1+7.pem --source 4343 --target 8101",
...
}
for my local development.
and i need to restart dev:wrangler script whenever there any changes happen in my D1 records.
i'm still blessed with the current nitro & don't have any problems. but it will makes nitro better if i don't have to do restart so often.
EDIT:
sorry, it doesn't relate. i need to restart whenever any changes happen in my D1 records because my route is served from cache.
it's because i use Cached Event Handler ↗ defineCachedEventHandler instead of defineEventHandler for my route.
Use of cloudflare bindings is currently documented: https://nitro.build/deploy/providers/cloudflare#direct-access-to-cloudflare-bindings
dev-preset is on the roadmap.