From 00233280d45a2fa87c4c01b9086620606be210e1 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Wed, 4 Mar 2026 15:11:25 -0500 Subject: [PATCH] feat(backend): add DotEnv class for loading environment variables from .env file --- SharpbinV3.Server/DotEnv.cs | 24 ++++++++++++++++++++++++ SharpbinV3.Server/Program.cs | 1 + 2 files changed, 25 insertions(+) create mode 100644 SharpbinV3.Server/DotEnv.cs diff --git a/SharpbinV3.Server/DotEnv.cs b/SharpbinV3.Server/DotEnv.cs new file mode 100644 index 0000000..a14ed52 --- /dev/null +++ b/SharpbinV3.Server/DotEnv.cs @@ -0,0 +1,24 @@ +namespace SharpbinV3.Server +{ + /// + /// https://dusted.codes/dotenv-in-dotnet + /// + public static class DotEnv + { + public static void Load(string filePath) + { + if (!File.Exists(filePath)) + return; + + foreach (var line in File.ReadAllLines(filePath)) + { + var parts = line.Split('=', StringSplitOptions.RemoveEmptyEntries); + + if (parts.Length != 2) + continue; + + Environment.SetEnvironmentVariable(parts[0], parts[1]); + } + } + } +} diff --git a/SharpbinV3.Server/Program.cs b/SharpbinV3.Server/Program.cs index 0370d29..8ec6ec9 100644 --- a/SharpbinV3.Server/Program.cs +++ b/SharpbinV3.Server/Program.cs @@ -24,6 +24,7 @@ namespace SharpbinV3.Server { public static void Main(string[] args) { + DotEnv.Load(".env"); var builder = WebApplication.CreateBuilder(args); // Add services to the container.