Added simple env var import

This commit is contained in:
Niggl1999 2020-06-04 09:54:10 +02:00
parent 7ffc5962b7
commit 5badaa819a

View File

@ -26,6 +26,13 @@ namespace ScrumTaskboard
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Get all the env vars for the DB connection
string dbHost = Environment.GetEnvironmentVariable("DATABASE_HOST");
string dbPort = Environment.GetEnvironmentVariable("DATABASE_PORT");
string dbName = Environment.GetEnvironmentVariable("DATABASE_NAME");
string dbUser = Environment.GetEnvironmentVariable("DATABASE_USER");
string dbPassword = Environment.GetEnvironmentVariable("DATABASE_PASSWORD");
services.AddCors(o => o.AddPolicy("AllowAll", builder => services.AddCors(o => o.AddPolicy("AllowAll", builder =>
{ {
builder.AllowAnyOrigin() builder.AllowAnyOrigin()
@ -34,7 +41,7 @@ namespace ScrumTaskboard
})); }));
services.AddScoped(serviceProvider => new TaskContext( services.AddScoped(serviceProvider => new TaskContext(
new DbContextOptionsBuilder<TaskContext>() new DbContextOptionsBuilder<TaskContext>()
.UseNpgsql("Host=nig.gl; Port=8543; Username=scrum; Database=taskboard; Password=c6gXud7YvBWp2sgxSgy4wRN") .UseNpgsql($"Host={dbHost}; Port={dbPort}; Username={dbUser}; Database={dbName}; Password={dbPassword}")
.Options)); .Options));
services.AddControllers(); services.AddControllers();
} }