Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature?]: Wrangler/Miniflare dev server for Cloudflare #1394

Open
2 tasks done
rvlzzr opened this issue Mar 15, 2024 · 4 comments
Open
2 tasks done

[Feature?]: Wrangler/Miniflare dev server for Cloudflare #1394

rvlzzr opened this issue Mar 15, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@rvlzzr
Copy link
Contributor

rvlzzr commented Mar 15, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

Solid-start's dev server doesn't use wrangler or miniflare for the Cloudflare presets, so bindings aren't available etc and it isn't really usable.

There's a hacky example in vinxi of react ssr with a miniflare 2 dev server, but miniflare 2 is 3 years out-of-date and is missing a lot of things, to even get D1 to work you have to prefix the binding with __D1_BETA__ etc.

Examples 🌈

Can the dev server under Cloudflare use https://developers.cloudflare.com/workers/wrangler/api/#getplatformproxy perhaps?

Sveltekit is doing this: https://github.com/sveltejs/kit/pull/11732/files#diff-78806028d48ad47894445421562b7796c53178948c017e13d4550def4193903e

Motivation 🔦

Solid-start DX with Cloudflare is currently miserable.

@rvlzzr rvlzzr added the enhancement New feature or request label Mar 15, 2024
@rvlzzr
Copy link
Contributor Author

rvlzzr commented Mar 16, 2024

It seems you can just do something like the following in middleware, but still I think this is something that should be handled by the framework so process.env works consistently in dev/prod, or at least documented.

if (import.meta.env.PROD) {
  event.locals.db = process.env.DB;
} else {
  const wrangler = await import("wrangler");
  const proxy = await wrangler.getPlatformProxy();
  event.locals.db = proxy.env.DB;
}

@ryansolid
Copy link
Member

Yeah since we don't control the adapters/presets this is a bit more tricky then in the past (or in Sveltekit). It was one of the tradeoffs of going this way, but I hope to have a solution in the future.

@mattp0123
Copy link

There's an Access to the bindings in local env section in Nitro docs. But it doesn't seem to work with Solid Start, according to nitrojs/nitro-cloudflare-dev#42

@ryansolid
Copy link
Member

Yeah Nitro added some newer features to support this. We don't use Nitro currently in dev with Vinxi so this won't work. I'm hoping after Vite 6 core Vite(and in so Nitro) will have the features we need to change up this setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants