-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathProgram.cs
49 lines (39 loc) · 1.41 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
using KCert;
using KCert.Services;
using System.Reflection;
// command line option for manually generating an ECDSA key
if (args.Length > 0 && args[^1] == "generate-key")
{
Console.WriteLine("Generating ACME Key");
var key = CertClient.GenerateNewKey();
Console.WriteLine(key);
return;
}
var builder = WebApplication.CreateBuilder(args);
// Add all services marked with the [Service] attribute
Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.GetCustomAttribute<ServiceAttribute>() != null)
.ToList().ForEach(t => builder.Services.AddSingleton(t));
builder.Services.AddSingleton(s => s.GetRequiredService<KubernetesFactory>().GetClient());
builder.Services.AddConnections();
builder.Services.AddControllersWithViews();
builder.WebHost.ConfigureKestrel(opt =>
{
opt.ListenAnyIP(80);
opt.ListenAnyIP(8080);
});
// add background services
builder.Services.AddHostedService<RenewalService>();
builder.Services.AddHostedService<IngressMonitorService>();
builder.Services.AddHostedService<ConfigMonitorService>();
var app = builder.Build();
app.MapWhen(c => c.Connection.LocalPort == 8080, b =>
{
b.UseStaticFiles();
b.UseRouting().UseEndpoints(e => e.MapControllers());
});
app.MapWhen(c => c.Connection.LocalPort == 80 && c.Request.Path.HasValue && c.Request.Path.Value.StartsWith("/.well-known/acme-challenge"), b =>
{
b.UseRouting().UseEndpoints(e => e.MapControllers());
});
app.Run();