-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
56 lines (45 loc) · 1.54 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
using PlanningPoker.Server;
using StackExchange.Redis;
var builder = WebApplication.CreateBuilder(
new WebApplicationOptions {
Args = args,
ContentRootPath = "./"
}
);
if (Environment.GetEnvironmentVariable("PORT") is not null and { Length: > 0 } portVar && int.TryParse(portVar, out int port)) {
builder.WebHost.ConfigureKestrel(
options => {
options.ListenAnyIP(port);
}
);
}
var signalRBuilder = builder.Services.AddSignalR();
if (builder.Configuration.GetConnectionString("Redis") is string redisConnectionString && !string.IsNullOrEmpty(redisConnectionString)) {
builder.Services.AddSingleton<IConnectionMultiplexer>(await ConnectionMultiplexer.ConnectAsync(redisConnectionString));
builder.Services.AddTransient(s => s.GetRequiredService<IConnectionMultiplexer>().GetDatabase());
builder.Services.AddTransient<IStore, RedisStore>();
signalRBuilder.AddStackExchangeRedis(
redisConnectionString,
options => options.Configuration.ChannelPrefix = RedisChannel.Literal("signalr_prod")
);
}
else {
builder.Services.AddTransient<IStore, InMemoryStore>();
}
signalRBuilder.AddMessagePackProtocol();
builder.Services.AddRazorPages();
var app = builder.Build();
if (app.Environment.IsDevelopment()) {
app.UseWebAssemblyDebugging();
}
else {
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages();
app.MapHub<SessionHub>("/sessions/hub");
app.MapFallbackToFile("index.html");
app.Run();