import { load } from "@std/dotenv"; import { parse } from "jsr:@std/yaml"; import { log } from "./log.ts"; const dirname = Deno.cwd(); await load({ envPath: `${dirname}/.env`, export: true }); let staticUsers: { [key: string]: string } = {}; try { const yamlContent = await Deno.readTextFile(`${dirname}/users.yaml`); const parsedContent = parse(yamlContent); if (parsedContent !== null && typeof parsedContent === "object") { staticUsers = parsedContent as { [key: string]: string }; log(`Serving content for pubkeys in users.yaml`, "blue"); } } catch { log(`Could not find or parse a users.yaml config`, "yellow"); } const config = { port: parseInt(Deno.env.get("PORT") || "8000"), base_url: Deno.env.get("BASE_URL") || `http://localhost:8000`, relay_urls: Deno.env.get("RELAY_URLS")?.split(",") || [], staticUsers, ldapEnabled: !!Deno.env.get("LDAP_URL"), ldap: { url: Deno.env.get("LDAP_URL"), bindDN: Deno.env.get("LDAP_BIND_DN"), password: Deno.env.get("LDAP_PASSWORD"), searchDN: Deno.env.get("LDAP_SEARCH_DN"), }, }; if (config.relay_urls.length === 0) { log(`No relays configured. Please add at least one relay to RELAY_URLS.`); Deno.exit(1); } if (config.ldapEnabled) { if ( config.ldap.url && config.ldap.bindDN && config.ldap.password && config.ldap.searchDN ) { log(`Serving content for pubkeys from ${config.ldap.url}`, "blue"); } else { log(`The LDAP config is incomplete`); Deno.exit(1); } } else { log(`LDAP not enabled`, "blue"); } if (Object.keys(staticUsers).length === 0 && !config.ldapEnabled) { log(`Neither static users nor LDAP configured. Nothing to serve.`); Deno.exit(1); } export default config;