mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat(backend): add DotEnv class for loading environment variables from .env file
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
namespace SharpbinV3.Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// https://dusted.codes/dotenv-in-dotnet
|
||||||
|
/// </summary>
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ namespace SharpbinV3.Server
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
DotEnv.Load(".env");
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|||||||
Reference in New Issue
Block a user