-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
127 lines (94 loc) · 3.35 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using demo;
using demo.Components;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.HttpOverrides;
using Repositories;
using System.Net;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddLettuceEncrypt();
builder.WebHost.UseWebRoot("wwwroot").UseStaticWebAssets();
//builder.WebHost.UseStaticWebAssets();
builder.WebHost.UseKestrel(k =>
{
IServiceProvider appServices = k.ApplicationServices;
k.Listen(
IPAddress.Any, 443,
o => o.UseHttps(h =>
{
h.UseLettuceEncrypt(appServices);
}));
});
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services
.AddScoped<AuthenticationStateProvider, CustomAuthenticationStateProvider>();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options => {
});
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("Bearer", policy =>
policy.Requirements.Add(new CustomAuthenticationRequirement()));
options.DefaultPolicy = options.GetPolicy("Bearer");
});
builder.Services.AddSingleton<UserRepository>();
builder.Services.AddSingleton<IAuthorizationHandler, CustomAuthenticationHandler>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddMvc();
builder.Services.AddOpenApi();
builder.Services.AddHttpClient("LocalApi", client => client.BaseAddress =
new Uri("https://serverless.network"));
//builder.WebHost.UseStaticWebAssets();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI(options => {
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
});
app.UseRouting();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.MapOpenApi();
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.UseAuthentication();
app.UseAuthorization();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.UseEndpoints(endpoints => {
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}"
);
endpoints.MapControllerRoute(
name: "list-post",
pattern: "{controller=Post}/{action=List}/[:username]"
);
// A different path is necessary for the API...
endpoints.MapBlazorHub("/websockets");
});
app.MapRazorPages();
app.UseForwardedHeaders(new ForwardedHeadersOptions {
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
//app.UsePathBase("/opt/publish");
/*app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider($@"{AppDomain.CurrentDomain.BaseDirectory}/wwwroot")
});*/
app.UseStaticFiles();
app.Run();