Commit 2816342 1 parent 3a81c6f commit 2816342 Copy full SHA for 2816342
File tree 4 files changed +44
-12
lines changed
templates/unstable-vite-cloudflare
4 files changed +44
-12
lines changed Original file line number Diff line number Diff line change 1
1
/// <reference types="@remix-run/cloudflare" />
2
2
/// <reference types="vite/client" />
3
-
4
- import type { KVNamespace } from "@cloudflare/workers-types" ;
5
-
6
- declare module "@remix-run/cloudflare" {
7
- interface AppLoadContext {
8
- env : {
9
- MY_KV : KVNamespace ;
10
- } ;
11
- }
12
- }
Original file line number Diff line number Diff line change @@ -4,8 +4,9 @@ import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages";
4
4
// @ts -ignore - the server build file is generated by `remix vite:build`
5
5
// eslint-disable-next-line import/no-unresolved
6
6
import * as build from "../build/server" ;
7
+ import { getLoadContext } from "../load-context" ;
7
8
8
9
export const onRequest = createPagesFunctionHandler ( {
9
10
build,
10
- getLoadContext : ( context ) => ( { env : context . env } ) ,
11
+ getLoadContext,
11
12
} ) ;
Original file line number Diff line number Diff line change
1
+ import type { KVNamespace } from "@cloudflare/workers-types" ;
2
+ import { type AppLoadContext } from "@remix-run/cloudflare" ;
3
+
4
+ // In the future, types for bindings will be generated by `wrangler types`
5
+ // See https://github.com/cloudflare/workers-sdk/pull/4931
6
+ type Bindings = {
7
+ // Add types for bindings configured in `wrangler.toml`
8
+ MY_KV : KVNamespace ;
9
+ } ;
10
+
11
+ declare module "@remix-run/cloudflare" {
12
+ interface AppLoadContext {
13
+ env : Bindings ;
14
+
15
+ extra : string ; // Example of augmenting load context
16
+ }
17
+ }
18
+
19
+ // Subset of Cloudflare context supported by `getBindingsProxy` for use in Node-based environments like Vite
20
+ // The Cloudflare team is working to improve their Node proxies to support:
21
+ // - https://github.com/cloudflare/workers-sdk/issues/4875
22
+ // - https://github.com/cloudflare/workers-sdk/issues/4876
23
+ // - https://github.com/cloudflare/workers-sdk/issues/4879
24
+ type Context = { request : Request ; env : Bindings } ;
25
+
26
+ // Shared implementation compatible with Vite, Wrangler, and Cloudflare Pages
27
+ export const getLoadContext = async (
28
+ context : Context
29
+ ) : Promise < AppLoadContext > => {
30
+ return {
31
+ ...context ,
32
+ extra : "stuff" , // Example of augmenting load context
33
+ } ;
34
+ } ;
Original file line number Diff line number Diff line change @@ -4,11 +4,18 @@ import {
4
4
} from "@remix-run/dev" ;
5
5
import { defineConfig } from "vite" ;
6
6
import tsconfigPaths from "vite-tsconfig-paths" ;
7
+ import { getBindingsProxy } from "wrangler" ;
8
+
9
+ import { getLoadContext } from "./load-context" ;
7
10
8
11
export default defineConfig ( {
9
12
plugins : [
10
13
remix ( {
11
- presets : [ cloudflare ( ) ] ,
14
+ presets : [
15
+ cloudflare ( getBindingsProxy , {
16
+ getRemixDevLoadContext : getLoadContext ,
17
+ } ) ,
18
+ ] ,
12
19
} ) ,
13
20
tsconfigPaths ( ) ,
14
21
] ,
You can’t perform that action at this time.
0 commit comments