-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.ts
35 lines (33 loc) · 1.15 KB
/
server.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
import { createRequestHandler, type ServerBuild } from 'react-router'
import * as build from './build/server'
import { getLoadContext } from './load-context'
const requestHandler = createRequestHandler(build as unknown as ServerBuild)
export default {
async fetch(request, env, ctx) {
try {
const loadContext = getLoadContext({
request,
context: {
cloudflare: {
// This object matches the return value from Wrangler's
// `getPlatformProxy` used during development via Remix's
// `cloudflareDevProxyVitePlugin`:
// https://developers.cloudflare.com/workers/wrangler/api/#getplatformproxy
// @ts-ignore
cf: request.cf,
ctx: {
waitUntil: ctx.waitUntil.bind(ctx),
passThroughOnException: ctx.passThroughOnException.bind(ctx),
},
caches,
env,
},
},
})
return await requestHandler(request, loadContext)
} catch (error) {
console.log(error)
return new Response('An unexpected error occurred', { status: 500 })
}
},
} satisfies ExportedHandler<Env>