dotnet: check env variables at startup

This commit is contained in:
pabloFuente 2024-05-08 14:08:28 +02:00
parent cba4a43392
commit 6edb8e6a4f

View File

@ -15,7 +15,7 @@ IConfiguration config = new ConfigurationBuilder()
// Load env variables
var SERVER_PORT = config.GetValue<int>("SERVER_PORT");
var LIVEKIT_API_KEY = config.GetValue<string>("LIVEKIT_API_KEY");
var LIVEKIT_API_SECRET = config.GetValue<string>("LIVEKIT_API_SECRET"); // ATTENTION! Make sure that this string is at least 32 characters long
var LIVEKIT_API_SECRET = config.GetValue<string>("LIVEKIT_API_SECRET");
// Enable CORS support
builder.Services.AddCors(options =>
@ -74,4 +74,15 @@ string CreateLiveKitJWT(string roomName, string participantName)
return new JwtSecurityTokenHandler().WriteToken(token);
}
app.Run();
if (LIVEKIT_API_KEY == null || LIVEKIT_API_SECRET == null)
{
Console.Error.WriteLine("\nERROR: LIVEKIT_API_KEY and LIVEKIT_API_SECRET not set\n");
Environment.Exit(1);
}
if (LIVEKIT_API_SECRET.Length < 32)
{
Console.Error.WriteLine("\nERROR: LIVEKIT_API_SECRET must be at least 32 characters long\n");
Environment.Exit(1);
}
app.Run();