-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
32 lines (28 loc) · 913 Bytes
/
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
import { logDevReady } from "@remix-run/cloudflare";
import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages";
import * as build from "@remix-run/dev/server-build";
// https://github.com/remix-run/remix/issues/6868#issuecomment-1711878481
import { z } from "zod";
export const AppEnvSchema = z.object({
SESSION_SECRET: z.string(),
DISCORD_AUTH_CLIENT_ID: z.string(),
DISCORD_AUTH_CLIENT_SECRET: z.string(),
DISCORD_AUTH_CALLBACK_URL: z.string(),
DB: z.custom<D1Database>((value) => Boolean(value)),
});
declare module "@remix-run/cloudflare" {
interface AppLoadContext {
env: z.output<typeof AppEnvSchema>;
}
}
if (process.env.NODE_ENV === "development") {
logDevReady(build);
}
export const onRequest = createPagesFunctionHandler({
build,
getLoadContext: (context) => {
const env = AppEnvSchema.parse(context.env);
return { env };
},
mode: build.mode,
});