Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Jan 18, 2024
1 parent ac8346a commit 6da77a9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
24 changes: 24 additions & 0 deletions templates/unstable-vite-cloudflare/.cloudflare/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This directory provides a temporary implementation of CloudFlare's [`getBindingsProxy` API][get-bindings-proxy].

Once [CloudFlare ships that feature][get-bindings-proxy], Remix will export a CloudFlare adapter that you can use:

```ts
// vite.config.ts
import { adapter as cloudflare } from "@remix-run/cloudflare";
import { vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [
remix({
adapter: cloudflare({
bindings: {
/* ... */
},
}),
}),
],
});
```

[get-bindings-proxy]: https://github.com/cloudflare/workers-sdk/pull/4523
11 changes: 2 additions & 9 deletions templates/unstable-vite-cloudflare/.cloudflare/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
// Eventually, `getCloudflareDevBindings` will be replaced by the official `getBindingsProxy` API from CloudFlare
// https://github.com/cloudflare/workers-sdk/pull/4523
// At that point, Remix will absorb this adapter so you can import it directly in your `vite.config.ts`:
//
// import { adapter as cloudflare } from "@remix-run/cloudflare"
//
// Until then, this `.cloudflare/` directory provides the adapter implementation.
import { DevBindingsOptions, getCloudflareDevBindings } from "./bindings";
import { DevBindingsOptions, getBindingsProxy } from "./bindings";

export const adapter =
(options?: { bindings: DevBindingsOptions }) => async () => {
let bindings: Record<string, unknown> | undefined;
if (options?.bindings) {
bindings = await getCloudflareDevBindings(options.bindings);
bindings = await getBindingsProxy(options.bindings);
}
let loadContext = bindings && { env: bindings };
return { loadContext };
Expand Down
2 changes: 1 addition & 1 deletion templates/unstable-vite-cloudflare/.cloudflare/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type DevBindingsOptions = {
persist?: false | string;
};

export async function getCloudflareDevBindings(options: DevBindingsOptions) {
export async function getBindingsProxy(options: DevBindingsOptions) {
let mf = await instantiateMiniflare(options);
let bindings = await mf.getBindings();
return bindings;
Expand Down
2 changes: 2 additions & 0 deletions templates/unstable-vite-cloudflare/.cloudflare/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// If you're wondering what this code is all about, check out the README.md in this directory!
export { adapter } from "./adapter";
4 changes: 3 additions & 1 deletion templates/unstable-vite-cloudflare/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { unstable_vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

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

export default defineConfig({
plugins: [
Expand Down

0 comments on commit 6da77a9

Please sign in to comment.