solidjs / solid-start

SolidStart, the Solid app framework
https://start.solidjs.com
MIT License
5.04k stars 376 forks source link

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

Open rvlzzr opened 5 months ago

rvlzzr commented 5 months ago

Duplicates

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 commented 5 months ago

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 commented 5 months ago

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.