-
Notifications
You must be signed in to change notification settings - Fork 4
/
Program.cs
96 lines (74 loc) · 2.72 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#region (c) 2023 Joseph Shook. All rights reserved.
// /*
// Authors:
// Joseph Shook [email protected]
//
// See LICENSE in the project root for license information.
// */
#endregion
using Microsoft.AspNetCore.Hosting.StaticWebAssets;
using Microsoft.EntityFrameworkCore;
using MudBlazor.Services;
using Udap.CA.DbContexts;
using Udap.CA.Services;
using Udap.CA.Services.State;
using Serilog;
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
Log.Information("Starting up");
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((ctx, lc) => lc
.WriteTo.Console(
outputTemplate:
"[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}")
.Enrich.FromLogContext()
.ReadFrom.Configuration(ctx.Configuration));
builder.Configuration.AddJsonFile("/secret/udap-ca_appsettings", true, false);
StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration);
var provider = builder.Configuration.GetValue("provider", "SqlServer");
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddMudServices();
builder.Services.AddAutoMapper(typeof(Program));
_ = provider switch
{
"sqlite" => builder.Services.AddDbContext<IUdapCaContext, UdapCaContext>(
options => options.UseSqlite(connectionString)
.LogTo(Console.WriteLine, LogLevel.Information)),
"SqlServer" => builder.Services.AddDbContext<IUdapCaContext, UdapCaContext>(
options => options.UseSqlServer(connectionString)
.LogTo(Console.WriteLine, LogLevel.Information)),
_ => throw new Exception($"Unsupported provider: {provider}")
};
builder.Services.AddSingleton<CommunityState>();
builder.Services.AddScoped<CommunityService>();
builder.Services.AddScoped<RootCertificateService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Unhandled exception");
}
finally
{
Log.Information("Shut down completed");
Log.CloseAndFlush();
}