-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
94 lines (70 loc) · 2.6 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
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using CarpentryShop.Services;
using CarpentryShop.Areas.Identity.Data;
using Microsoft.AspNetCore.HttpOverrides;
using System.Net;
var builder = WebApplication.CreateBuilder(args);
var connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION");
if (string.IsNullOrEmpty(connectionString))
{
throw new Exception("DB_CONNECTION environment variable is not set; Please set the environment variable");
}
builder.Services.AddDbContext<CarpentryShopIdentityDbContext>(options =>
options.UseNpgsql(connectionString));
builder.Services.AddDbContext<CarpentryShopIdentityDbContext>(options =>
options.UseNpgsql(connectionString));
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<CarpentryShopIdentityDbContext>();
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
var emailSection = builder.Configuration.GetSection("EmailSettings");
builder.Services.Configure<EmailSettings>(emailSection);
builder.Services.AddSingleton<IEmailSender, EmailSender>();
builder.Services.AddRazorPages(options =>
{
options.Conventions.AuthorizePage("/Admin/Index");
});
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.KnownProxies.Add(IPAddress.Parse("127.0.0.1"));
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
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();
}
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<CarpentryShopIdentityDbContext>();
context.Database.EnsureCreated();
// DbInitializer.Initialize(context);
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
// using Microsoft.AspNetCore.HttpOverrides;
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseAuthentication();
app.UseAuthorization();
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
await SampleData.InitializeAsync(services);
}
app.MapRazorPages();
app.Run();