Replies: 12 comments 34 replies
-
Agree, with the notes above. Local development is very inefficient atm.
The major drawback of that solution is that complete rebulding of the project (first process) takes too long ~12 sec. Another possible solution to look intoI found out that That would make the workaround a perfectly working solution which we could suggest in the Docs. Unfortunately, atm the rollup watch mode doesn't work. When I specify the watcher
running I'm not sure, but this Error probably comes from the fact that SSR artifacts are moved by Cloudflare integration plugin to a different place - WDYT? Maybe there is a quick fix which would enable |
Beta Was this translation helpful? Give feedback.
-
Cloudflare has recently provided proxy bindings https://github.com/james-elicx/cf-bindings-proxy
GitHub issue here: Current state of other frameworksAlso remix installed with `npm create cloudflare@latest` supports cloudflare bindings in development
but astro |
Beta Was this translation helpful? Give feedback.
-
I'm in the process of developing a solution for this issue and would like to gather community feedback to prioritize features more effectively. I'm considering two types of bindings, each with its own set of advantages. Both options are on the roadmap, but integrating both will require additional development time. I'd love to hear your thoughts on which feature should be prioritized. Your input will help guide the development process. A) Mocked BindingsWhat it is: An emulation of the bindings running locally, similar to the approach taken in Miniflare v2. B) Remote Bindings on Cloudflare (CF)What it is: Proxied bindings on Cloudflare that run on Cloudflare's infrastructure and share the same data, similar to the approach taken by proxy/bridge solutions. |
Beta Was this translation helpful? Give feedback.
-
We've added support for https://docs.astro.build/en/guides/integrations-guide/cloudflare/#runtime |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi, 2 questions
It seems like whenever i tried to access it with astro dev command, it does not pick up any information from my D1 database, either remote or local astro dev does not pick up the local data from .wrangler files for D1 data When I use drizzle-orm to query the users for example, it says no table exist
But there's no data in the D1 database somehow. Here's my wrangler.toml |
Beta Was this translation helpful? Give feedback.
-
You should be able to apply those migrations using wrangler cli and then use them in Astro |
Beta Was this translation helpful? Give feedback.
-
Can we use cloudflare's production d1 and r2 bindings with HMR on astro dev? |
Beta Was this translation helpful? Give feedback.
-
By no means a complete solution but something that could be a stepping stone to make it easier to access Cloudflare bindings globally / outside of Example[[d1_databases]]
binding = "D1"
database_name = "D1"
database_id = "D1"
preview_database_id = "D1" import { getBindingsProxy } from "wrangler";
const { bindings, dispose } = await getBindingsProxy();
const db = bindings.D1;
// ^? D1Database |
Beta Was this translation helpful? Give feedback.
-
I have two local sqlite files
❯ ls .wrangler/state/v3/d1/miniflare-D1DatabaseObject/
0a7ef88a919d8075ad9accd397b88822659af4c7329d4875c4d20d0bb34fbce1.sqlite
e7352547963de7050bd7d94658afc4fe78b61811b7815da12d90be8e863abf4d.sqlite Can I get astro and wrangler to access the same local file? These seem to be related: |
Beta Was this translation helpful? Give feedback.
-
This proposal is effectively implemented. We'll continue to invest time into making it more robust and add more bindings over time. We also are actively working to try using a real Cloudflare runtime to get a 1:1 dev/prod match. If you find any bugs/issues please open an issue at https://github.com/withastro/adapters/issues |
Beta Was this translation helpful? Give feedback.
-
Does this work for static sites or just SSR? I have a static site deployed to pages with a GPT chat page running on a cloudflare function and am trying to figure out how to run a local dev mode with access to my function. In the Astro Discord server I was told that this adapter only works for SSR sites, so I guess I'm out of luck? I did try enabling platformProxy anyway but had no luck running my function locally. I am only able to do so with the deprecated Is there another solution for a static site or am I misunderstanding something? I suppose I'd have to create my own script using This is my export default defineConfig({
adapter: cloudflare({
runtime: {
mode: 'local',
},
platformProxy: {
enabled: true,
},
}),
output: 'server', I tried runtime with mode set to local but this doesn't seem to be a valid option. It didn't work regardless. |
Beta Was this translation helpful? Give feedback.
-
Summary
Introduce the ability to utilize Cloudflare bindings such as KV, DO, R2, Durable Objects, etc., during local development within the Astro framework.
Background & Motivation
Currently there's a gap in the local development workflow when using Astro with Cloudflare, specifically when attempting to access Cloudflare bindings. Presently, these bindings (KV, DO, R2, Durable Objects, etc.) are not accessible during local development and can only be accessed in a production build.
This lack of access during development inhibits developers from fully testing and integrating Cloudflare's functionalities into their projects before deploying to production. It leads to increased friction and inefficiency in the development process, as changes can only be tested in production builds. Consequently, developers are potentially deterred from fully leveraging the powerful features offered by the combination of Astro and Cloudflare.
Goals
Example
The proposed solution should allow the following code to correctly return the Cloudflare bindings during local development:
Notes
It's notable that Wrangler supports local development using tools like Miniflare and Workerd. This might suggest a potential path forward, not by having Astro mock Cloudflare, but rather by seeking closer integration with tools like Miniflare that are designed to provide a local development environment for Cloudflare Workers.
This issue is not unique, as it has surfaced in several discussions within both the Cloudflare and Astro communities. There seems to be a recurring need for better local testing support for Cloudflare bindings within Astro.
An additional point of consideration is the current Wrangler initialization process. As part of Wrangler v3, Astro is presented as a framework during setup. At the end of this process, developers are instructed to run astro dev via npm run dev, which calls wrangler pages dev with a proxy to astro dev. This flow can potentially give the impression that the bindings would work out of the box, which isn't the case currently. This part of the setup process could either be clarified or adjusted to reflect the true capabilities and limitations of the local development environment when it comes to Cloudflare bindings.
Beta Was this translation helpful? Give feedback.
All reactions