-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-context.ts
37 lines (31 loc) · 990 Bytes
/
load-context.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { PlatformProxy } from "wrangler";
import { drizzle } from "drizzle-orm/d1";
import { schema } from "./database/schema";
// `Env` is defined in worker-configuration.d.ts
type GetLoadContextArgs = {
request: Request;
context: {
cloudflare: Omit<
PlatformProxy<Env, IncomingRequestCfProperties>,
"dispose" | "caches"
> & {
caches:
| PlatformProxy<Env, IncomingRequestCfProperties>["caches"]
| CacheStorage;
};
};
};
declare module "react-router" {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface AppLoadContext extends ReturnType<typeof getLoadContext> {
// This will merge the result of `getLoadContext` into the `AppLoadContext`
}
}
// Shared implementation compatible with Vite, Wrangler, and Cloudflare Workers
export function getLoadContext({ context }: GetLoadContextArgs) {
const db = drizzle(context.cloudflare.env.DB, { schema });
return {
...context,
db,
};
}