feat: dotenv

This commit is contained in:
CyberL1 2024-03-03 14:15:39 +01:00
parent 408578e098
commit fe6a66601d
4 changed files with 10 additions and 4 deletions

1
Minecraft-Realms-Emulator/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

View File

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>

View File

@ -3,6 +3,13 @@ using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Helpers;
var builder = WebApplication.CreateBuilder(args);
DotNetEnv.Env.Load();
if (Environment.GetEnvironmentVariable("CONNECTION_STRING") == null)
{
Console.WriteLine("CONNECTION_STRING environment variable missing");
return;
}
// Add services to the container.
@ -13,7 +20,7 @@ builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<DataContext>(options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
options.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_STRING"));
});
var app = builder.Build();

View File

@ -1,7 +1,4 @@
{
"ConnectionStrings": {
"DefaultConnection": "User Id=postgres.aquqykciubzfolgrftwa;Password=z6hmYsiCl0f7HzUr;Server=aws-0-us-west-1.pooler.supabase.com;Port=5432;Database=postgres"
},
"Logging": {
"LogLevel": {
"Default": "Information",