generated from edmundhung/remix-cloudflare-template
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.ts
41 lines (34 loc) · 1.1 KB
/
index.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
38
39
40
41
import * as build from '../build/index.js';
import { createFetchHandler, createWorkerAssetHandler } from './adapter';
import { getPageStore } from './store/PageStore';
import { getUserStore } from './store/UserStore';
import { getResourceStore } from './store/ResourcesStore';
import { createSession } from './session';
import type { Env } from './types';
// Setup Durable Objects
export * from './store';
declare module '@remix-run/server-runtime' {
export interface AppLoadContext {
session: Context['session'];
resourceStore: Context['resourceStore'];
pageStore: Context['pageStore'];
userStore: Context['userStore'];
}
}
type Context = ReturnType<typeof getLoadContext>;
function getLoadContext(request: Request, env: Env, ctx: ExecutionContext) {
return {
session: createSession(request, env, ctx),
resourceStore: getResourceStore(env, ctx),
pageStore: getPageStore(env, ctx),
userStore: getUserStore(env, ctx),
};
}
const worker: ExportedHandler<Env> = {
fetch: createFetchHandler({
build,
getLoadContext,
handleAsset: createWorkerAssetHandler(build),
}),
};
export default worker;