-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
99 lines (77 loc) · 2.86 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
97
98
99
using Keycloak.AuthServices.Authentication;
using Keycloak.AuthServices.Authorization;
using Ljbc1994.Blazor.IntersectionObserver;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.EntityFrameworkCore;
using Microsoft.FluentUI.AspNetCore.Components;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using StatusDashboard.Components;
using StatusDashboard.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOptions<StatusOption>()
.BindConfiguration(nameof(StatusDashboard))
.ValidateDataAnnotations()
.ValidateOnStart();
if (!builder.Environment.IsDevelopment())
builder.Services.AddLettuceEncrypt();
builder.Services
.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddKeycloakWebApp(
builder.Configuration.GetSection(KeycloakAuthenticationOptions.Section),
configureOpenIdConnectOptions: x => {
x.SaveTokens = true;
x.ResponseType = OpenIdConnectResponseType.Code;
x.Events = new() {
OnSignedOutCallbackRedirect = context => {
context.Response.Redirect("/");
context.HandleResponse();
return Task.CompletedTask;
}
};
}
);
builder.Services
.AddAuthorization()
.AddKeycloakAuthorization(builder.Configuration);
builder.Services.AddDbContextFactory<StatusContext>(
x => x
.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))
.EnableDetailedErrors()
.EnableSensitiveDataLogging()
);
builder.Services.AddMemoryCache();
builder.Services.AddHttpClient<StatusHttp>();
builder.Services.AddHostedService<StatusService>();
builder.Services.AddScoped<SlaService>();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddControllers();
builder.Services.AddScoped(typeof(IEventManager<>), typeof(EventManager<>));
builder.Services.AddFluentUIComponents();
builder.Services.AddIntersectionObserver();
builder.Services.AddResponseCompression(x => x.EnableForHttps = true);
builder.Services.AddResponseCaching();
builder.Services.AddOutputCache(x => x.AddBasePolicy(b => b.Cache()));
var app = builder.Build();
if (!app.Environment.IsDevelopment()) {
app.UseExceptionHandler("/Error", true);
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseResponseCompression();
app.UseResponseCaching();
app.UseStaticFiles(new StaticFileOptions {
OnPrepareResponse = ctx => {
const int durationInSeconds = 60 * 60 * 24 * 30;
ctx.Context.Response.Headers["Cache-Control"] = $"no-cache, max-age={durationInSeconds}";
}
});
app.UseRouting();
app.UseAntiforgery();
app.UseOutputCache();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.MapControllers();
app.Run();