This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / web / src / lib / server / config.ts
2.0 kB 64 lines
1import { env } from "$env/dynamic/private"; 2 3const cleanUrl = (value: string | undefined, fallback: string) => { 4 const raw = value?.trim() || fallback; 5 return raw.replace(/\/+$/, ""); 6}; 7 8export type WebConfig = { 9 bobbinUrl: string; 10 knotMirrorUrl: string; 11 apiUrl: string; 12 knotResolverUrl: string; 13 camoUrl: string; 14 avatarUrl: string; 15 /** the secrets camo and avatar sign with, so neither leaves the server */ 16 camoSecret: string; 17 avatarSecret: string; 18}; 19 20export type PublicWebConfig = Pick< 21 WebConfig, 22 "bobbinUrl" | "knotMirrorUrl" | "apiUrl" | "knotResolverUrl" 23> & { 24 /** camo has a secret, so markup can route images through it */ 25 camoEnabled: boolean; 26}; 27 28type WebConfigEnv = { 29 BOBBIN_URL?: string; 30 KNOTMIRROR_URL?: string; 31 TANGLED_API_URL?: string; 32 API_URL?: string; 33 KNOT_RESOLVER_URL?: string; 34 CAMO_URL?: string; 35 CAMO_SHARED_SECRET?: string; 36 AVATAR_URL?: string; 37 AVATAR_SHARED_SECRET?: string; 38}; 39 40export const resolveConfig = (values: WebConfigEnv): WebConfig => ({ 41 bobbinUrl: cleanUrl(values.BOBBIN_URL, "http://127.0.0.1:8090"), 42 knotMirrorUrl: cleanUrl(values.KNOTMIRROR_URL, ""), 43 apiUrl: cleanUrl(values.TANGLED_API_URL ?? values.API_URL, "http://127.0.0.1:8080"), 44 knotResolverUrl: cleanUrl(values.KNOT_RESOLVER_URL, "https://knot1.tangled.sh"), 45 camoUrl: cleanUrl(values.CAMO_URL, "https://camo.tangled.sh"), 46 avatarUrl: cleanUrl(values.AVATAR_URL, "https://avatar.tangled.sh"), 47 camoSecret: values.CAMO_SHARED_SECRET?.trim() ?? "", 48 avatarSecret: values.AVATAR_SHARED_SECRET?.trim() ?? "" 49}); 50 51export const getConfig = (): WebConfig => resolveConfig(env as WebConfigEnv); 52 53// listed one by one, so anything new in WebConfig stays private until it is 54// named here 55export const getPublicConfig = (): PublicWebConfig => { 56 const config = getConfig(); 57 return { 58 bobbinUrl: config.bobbinUrl, 59 knotMirrorUrl: config.knotMirrorUrl, 60 apiUrl: config.apiUrl, 61 knotResolverUrl: config.knotResolverUrl, 62 camoEnabled: config.camoSecret !== "" 63 }; 64};