forked from openimis/rest_api_c-sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
66 lines (56 loc) · 2.43 KB
/
Program.cs
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
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OpenImis.Extensions.Configuration;
namespace OpenImis.RestApi
{
public class Program
{
public static void Main(string[] args)
{
var appRootPath = Directory.GetCurrentDirectory();
BuildWebHost(appRootPath, args).Run();
}
//public static IWebHost BuildWebHost(string[] args) =>
// WebHost.CreateDefaultBuilder(args)
// .UseStartup<Startup>()
// .Build();
public static IWebHost BuildWebHost(string appRootPath, string[] args)
{
var webHostBuilder = GetWebHostBuilder(appRootPath, args);
return webHostBuilder.Build();
}
public static IWebHostBuilder GetWebHostBuilder(string appRootPath, string[] args)
{
var webHostBuilder = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(appRootPath)
.ConfigureAppConfiguration((hostingContext, config) =>
{
//var secretsMode = GetSecretsMode(hostingContext.HostingEnvironment);
//config.AddOpenImisConfig(secretsMode, "REGISTRY_CONFIG_FILE");
//config.AddOpenImisConfig(SecretsMode.LocalFile, $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json");
config.AddJsonFile($"appsettings.json", optional: false, reloadOnChange: true);
config.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: false, reloadOnChange: true);
config.AddJsonFile("openImisModules.json", optional: true, reloadOnChange: true);
})
.UseStartup<Startup>();
return webHostBuilder;
}
private static SecretsMode GetSecretsMode(IHostingEnvironment env)
{
if (env.IsProduction())
return SecretsMode.DockerSecrets;
var useDockerSecrets = Environment.GetEnvironmentVariable("REGISTRY_USE_DOCKER_SECRETS");
if (useDockerSecrets != null && useDockerSecrets.Equals("false", StringComparison.OrdinalIgnoreCase))
return SecretsMode.LocalFile;
return SecretsMode.DockerSecrets;
}
}
}