Path: redb-route/demo/redb.Route.Demo/EnvLoader.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/redb.Route.Demo/EnvLoader.cs ---- using System.Runtime.CompilerServices; namespace redb.Route.Demo; /// /// Loads redb.Tsak/publish/keys/.env.local into /// on first assembly use, so the LLM demo routes find their API keys without /// the operator having to export them by hand. Existing environment variables /// are never overwritten — production containers that set keys via /// environment: in compose continue to win. /// /// Missing file = silent no-op (CI / fresh checkout). The lookup climbs from /// AppContext.BaseDirectory upwards looking for a sibling /// redb.Tsak/publish/keys/.env.local, matching the layout this repo uses. /// /// internal static class EnvLoader { [ModuleInitializer] internal static void Load() { var dir = AppContext.BaseDirectory; while (!string.IsNullOrEmpty(dir)) { var candidate = Path.Combine(dir, "redb.Tsak", "publish", "keys", ".env.local"); if (System.IO.File.Exists(candidate)) { Apply(candidate); return; } dir = Directory.GetParent(dir)?.FullName; } } private static void Apply(string path) { foreach (var rawLine in System.IO.File.ReadAllLines(path)) { var line = rawLine.Trim(); if (line.Length == 0 || line.StartsWith('#')) continue; var eq = line.IndexOf('='); if (eq <= 0) continue; var key = line[..eq].Trim(); var value = line[(eq + 1)..].Trim().Trim('"'); if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(key))) continue; Environment.SetEnvironmentVariable(key, value); } } }