Skip to content

Commit 6da77a9

Browse files
committed
pr feedback
1 parent ac8346a commit 6da77a9

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This directory provides a temporary implementation of CloudFlare's [`getBindingsProxy` API][get-bindings-proxy].
2+
3+
Once [CloudFlare ships that feature][get-bindings-proxy], Remix will export a CloudFlare adapter that you can use:
4+
5+
```ts
6+
// vite.config.ts
7+
import { adapter as cloudflare } from "@remix-run/cloudflare";
8+
import { vitePlugin as remix } from "@remix-run/dev";
9+
import { defineConfig } from "vite";
10+
11+
export default defineConfig({
12+
plugins: [
13+
remix({
14+
adapter: cloudflare({
15+
bindings: {
16+
/* ... */
17+
},
18+
}),
19+
}),
20+
],
21+
});
22+
```
23+
24+
[get-bindings-proxy]: https://github.com/cloudflare/workers-sdk/pull/4523

templates/unstable-vite-cloudflare/.cloudflare/adapter.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
// Eventually, `getCloudflareDevBindings` will be replaced by the official `getBindingsProxy` API from CloudFlare
2-
// https://github.com/cloudflare/workers-sdk/pull/4523
3-
// At that point, Remix will absorb this adapter so you can import it directly in your `vite.config.ts`:
4-
//
5-
// import { adapter as cloudflare } from "@remix-run/cloudflare"
6-
//
7-
// Until then, this `.cloudflare/` directory provides the adapter implementation.
8-
import { DevBindingsOptions, getCloudflareDevBindings } from "./bindings";
1+
import { DevBindingsOptions, getBindingsProxy } from "./bindings";
92

103
export const adapter =
114
(options?: { bindings: DevBindingsOptions }) => async () => {
125
let bindings: Record<string, unknown> | undefined;
136
if (options?.bindings) {
14-
bindings = await getCloudflareDevBindings(options.bindings);
7+
bindings = await getBindingsProxy(options.bindings);
158
}
169
let loadContext = bindings && { env: bindings };
1710
return { loadContext };

templates/unstable-vite-cloudflare/.cloudflare/bindings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type DevBindingsOptions = {
2020
persist?: false | string;
2121
};
2222

23-
export async function getCloudflareDevBindings(options: DevBindingsOptions) {
23+
export async function getBindingsProxy(options: DevBindingsOptions) {
2424
let mf = await instantiateMiniflare(options);
2525
let bindings = await mf.getBindings();
2626
return bindings;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// If you're wondering what this code is all about, check out the README.md in this directory!
2+
export { adapter } from "./adapter";

templates/unstable-vite-cloudflare/vite.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { unstable_vitePlugin as remix } from "@remix-run/dev";
22
import { defineConfig } from "vite";
33
import tsconfigPaths from "vite-tsconfig-paths";
44

5-
import { adapter as cloudflare } from "./.cloudflare/adapter";
5+
// Check out .cloudflare/README.md for why there's a `.cloudflare` directory in this template
6+
// In the future, you'll be able to import the `cloudflare` adapter from `@remix-run/cloudflare`
7+
import { adapter as cloudflare } from "./.cloudflare";
68

79
export default defineConfig({
810
plugins: [

0 commit comments

Comments
 (0)