Skip to content

Commit 4cce218

Browse files
Remove config file check at app startup (#2889)
* Remove hard config file check in the docker app * Add explict call to AddEnvironmentVariables() when loading the config from file
1 parent 71bec63 commit 4cce218

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/Application/Program.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@
77
using Microsoft.Extensions.DependencyInjection;
88
using Microsoft.Extensions.Hosting;
99

10+
var builder = WebApplication.CreateBuilder();
1011

11-
// Load configuration
12-
if (args.Length != 1)
13-
{
14-
Console.Error.WriteLine("Usage: yarp.exe <config_file>");
15-
return 1;
16-
}
17-
var configFile = args[0];
18-
var fileInfo = new FileInfo(configFile);
19-
if (!fileInfo.Exists)
12+
// Load configuration from file if passed
13+
if (args.Length == 1)
2014
{
21-
Console.Error.WriteLine($"Could not find '{configFile}'.");
22-
return 2;
15+
var configFile = args[0];
16+
var fileInfo = new FileInfo(configFile);
17+
if (!fileInfo.Exists)
18+
{
19+
Console.Error.WriteLine($"Could not find '{configFile}'.");
20+
return 2;
21+
}
22+
builder.Configuration.AddJsonFile(fileInfo.FullName, optional: false, reloadOnChange: true);
23+
builder.Configuration.AddEnvironmentVariables();
2324
}
2425

25-
var builder = WebApplication.CreateBuilder();
26-
builder.Configuration.AddJsonFile(fileInfo.FullName, optional: false, reloadOnChange: true);
27-
2826
// Configure YARP
2927
builder.AddServiceDefaults();
3028
builder.Services.AddServiceDiscovery();

0 commit comments

Comments
 (0)