-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (51 loc) · 2.05 KB
/
Program.cs
File metadata and controls
65 lines (51 loc) · 2.05 KB
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
using BlazorApp1.Components;
using BlazorApp1.Services;
using Fido2NetLib;
using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
// Read secrets from Secrets Manager
builder.Configuration.AddUserSecrets<Program>();
// Read ServerName from configuration
var serverName = builder.Configuration["AppSettings:ServerName"];
builder.Services.AddSingleton<Fido2>(new Fido2(new Fido2Configuration
{
ServerDomain = "localhost",
ServerName = serverName,
Origins = new HashSet<string> { "https://localhost:5001" },
TimestampDriftTolerance = TimeSpan.FromMinutes(5).Seconds
}));
// Configure MongoDB settings from Secrets Manager
builder.Services.Configure<MongoDbSettings>(options =>
{
options.ConnectionString = builder.Configuration["MongoDB:ConnectionString"]
?? Environment.GetEnvironmentVariable("MongoDB_ConnectionString")
?? throw new InvalidOperationException("MongoDB:ConnectionString is not configured.");
options.DatabaseName = builder.Configuration["MongoDB:DatabaseName"]
?? Environment.GetEnvironmentVariable("MongoDB_DatabaseName")
?? throw new InvalidOperationException("MongoDB:DatabaseName is not configured.");
});
// Register MongoDbService
builder.Services.AddSingleton<MongoDbService>();
var app = builder.Build();
// Test MongoDB connection on startup
if (app.Environment.IsDevelopment())
{
var mongoDbService = app.Services.GetRequiredService<MongoDbService>();
Console.WriteLine("Connected to MongoDB database.");
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// 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.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();