import { load } from "@std/dotenv"; import { parse } from "jsr:@std/yaml"; import { log } from "./log.ts"; const dirname = new URL(".", import.meta.url).pathname; await load({ envPath: `${dirname}/.env`, export: true }); let staticUsers; try { const yamlContent = await Deno.readTextFile(`${dirname}/users.yaml`); staticUsers = parse(yamlContent); log(`Serving content for ${Object.keys(staticUsers).length} pubkeys from users.yaml`, "blue"); } catch { staticUsers = {}; log(`Could not find or parse a users.yaml config`, "yellow"); } const relay_urls = Deno.env.get("RELAY_URLS")?.split(","); const config = { port: Deno.env.get("PORT") || 8000, base_url: Deno.env.get("BASE_URL") || `http://localhost:8000`, relay_urls, staticUsers: 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.ldapEnabled && config.ldap.url) { log(`Serving content for pubkeys from ${config.ldap.url}`, "blue"); } 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); } if (config.relay_urls?.length > 0) { log(`Relays: ${config.relay_urls.join(", ")}`, "green"); } else { log(`No relays configured. Please add at least one relay to RELAY_URLS.`); Deno.exit(1); } export default config;