Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
48 lines (41 loc) · 1.7 KB
/
Copy pathProgram.cs
File metadata and controls
48 lines (41 loc) · 1.7 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
using System.Collections.Concurrent;
using System.Threading.Channels;
using be.Components;
using be.Data;
using be.Endpoints;
using be.Services;
using be.Game;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
var channels = new ConcurrentDictionary<int, Channel<Events>>();
var queue = new ConcurrentQueue<int>();
builder.Services.AddSingleton(channels);
builder.Services.AddSingleton(queue);
builder.Services.AddDbContextFactory<BeDataContext>(options => options.UseNpgsql(builder.Configuration.GetConnectionString("BeDataContext")));
builder.Services.AddRazorComponents();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
options.Cookie.Name = "becookie";
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
options.ExpireTimeSpan = new TimeSpan(10000, 1, 1, 1);
});
builder.Services.AddAuthorizationBuilder().SetFallbackPolicy(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddScoped<LoggedUser>();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}
app.UseStaticFiles();
app.UseAntiforgery();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorComponents<App>();
app.MapPost("user/create", User.Create).AllowAnonymous();
app.MapGet("game/events", Game.Events);
app.MapPost("game/start", Game.Start);
app.Run();