-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathConfig.cs
More file actions
55 lines (47 loc) · 1.87 KB
/
Config.cs
File metadata and controls
55 lines (47 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using dotenv.net;
namespace MAUITodo.Data;
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
public class EnvConfig
{
public string SupabaseUrl { get; set; }
public string SupabaseKey { get; set; }
public string SupabaseStorageUrl { get; set; }
public string PowerSyncUrl { get; set; }
public string BackendUrl { get; set; }
public string SupabaseUsername { get; set; }
public string SupabasePassword { get; set; }
public bool UseSupabase { get; set; }
public EnvConfig()
{
DotEnv.Load();
Console.WriteLine($"Current directory: {Directory.GetCurrentDirectory()}");
// Parse boolean value first
string useSupabaseStr = Environment.GetEnvironmentVariable("USE_SUPABASE") ?? "false";
if (!bool.TryParse(useSupabaseStr, out bool useSupabase))
{
throw new InvalidOperationException("USE_SUPABASE environment variable is not a valid boolean.");
}
UseSupabase = useSupabase;
if (UseSupabase)
Console.WriteLine("Using Supabase");
else
Console.WriteLine("Using Node");
PowerSyncUrl = GetRequiredEnv("POWERSYNC_URL");
if (UseSupabase)
{
SupabaseUrl = GetRequiredEnv("SUPABASE_URL");
SupabaseKey = GetRequiredEnv("SUPABASE_KEY");
SupabaseUsername = GetRequiredEnv("SUPABASE_USERNAME");
SupabasePassword = GetRequiredEnv("SUPABASE_PASSWORD");
}
else
{
BackendUrl = GetRequiredEnv("BACKEND_URL");
}
}
private static string GetRequiredEnv(string key)
{
return Environment.GetEnvironmentVariable(key)
?? throw new InvalidOperationException($"{key} environment variable is not set.");
}
}