Skip to content

Commit

Permalink
template
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Feb 14, 2024
1 parent d16d9a8 commit a15d6b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
4 changes: 2 additions & 2 deletions templates/vite-cloudflare/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { Form, useLoaderData } from "@remix-run/react";
const key = "__my-key__";

export async function loader({ context }: LoaderFunctionArgs) {
const { MY_KV } = context.env;
const { MY_KV } = context.cloudflare.env;
const value = await MY_KV.get(key);
return json({ value });
}

export async function action({ request, context }: ActionFunctionArgs) {
const { MY_KV: myKv } = context.env;
const { MY_KV: myKv } = context.cloudflare.env;

if (request.method === "POST") {
const formData = await request.formData();
Expand Down
12 changes: 5 additions & 7 deletions templates/vite-cloudflare/load-context.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { type KVNamespace } from "@cloudflare/workers-types";
import { type PlatformProxy } from "wrangler";

// In the future, types for bindings will be generated by `wrangler types`
// See https://github.com/cloudflare/workers-sdk/pull/4931
type Bindings = {
// Add types for bindings configured in `wrangler.toml`
MY_KV: KVNamespace;
};
// TODO: generate Env via `wrangler types`
type Env = { MY_KV: KVNamespace };
type Cloudflare = Omit<PlatformProxy<Env>, "dispose">;

declare module "@remix-run/cloudflare" {
interface AppLoadContext {
env: Bindings;
cloudflare: Cloudflare;
}
}
15 changes: 2 additions & 13 deletions templates/vite-cloudflare/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import {
vitePlugin as remix,
cloudflarePreset as cloudflare,
cloudflareProxyVitePlugin as remixCloudflareProxy,
} from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import { getBindingsProxy } from "wrangler";

export default defineConfig({
plugins: [
remix({
presets: [cloudflare(getBindingsProxy)],
}),
tsconfigPaths(),
],
ssr: {
resolve: {
externalConditions: ["workerd", "worker"],
},
},
plugins: [remixCloudflareProxy(), remix(), tsconfigPaths()],
});

0 comments on commit a15d6b6

Please sign in to comment.