Open History to see the last commit
1import { z } from "zod";
2export type Config = {
3 origin: string;
4 instanceID: string;
5 name: string;
6 authURL: string;
7 jwksURL: string;
8 clientID: string;
9 realtimeURL?: string;
10 realtimeSecret?: string;
11 databaseName: string;
12 photoBucket?: string;
13};
14export function config(env = process.env): Config {
15 const origin = z.url().parse(env.JOL_ORIGIN).replace(/\/$/, "");
16 if (
17 !origin.startsWith("https://") &&
18 !(
19 env.NODE_ENV !== "production" &&
20 /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)
21 )
22 )
23 throw new Error("JOL_ORIGIN must use HTTPS");
24 const authURL = z.url().parse(env.NEON_AUTH_BASE_URL).replace(/\/$/, "");
25 if (!authURL.startsWith("https://"))
26 throw new Error("Neon Auth must use HTTPS");
27 return {
28 origin,
29 instanceID: z.uuid().parse(env.JOL_INSTANCE_ID),
30 name: env.JOL_NAME || "Jerry On Line",
31 authURL,
32 jwksURL: env.NEON_AUTH_JWKS_URL || `${authURL}/.well-known/jwks.json`,
33 clientID: z.string().min(1).parse(env.JOL_OAUTH_CLIENT_ID),
34 realtimeURL: env.NEON_REALTIME_URL,
35 realtimeSecret: env.NEON_REALTIME_SECRET,
36 databaseName: env.DATABASE_URL
37 ? new URL(env.DATABASE_URL).pathname.slice(1)
38 : "neondb",
39 photoBucket: env.JOL_PHOTO_BUCKET,
40 };
41}