-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
109 lines (83 loc) · 2.84 KB
/
Program.cs
File metadata and controls
109 lines (83 loc) · 2.84 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
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
using HexStrategyInRazor.DB;
using HexStrategyInRazor.Managers;
using Microsoft.EntityFrameworkCore;
using System.Reflection;
namespace HexStrategyInRazor
{
public static class Program
{
private static WebApplication application;
public const string userIdCookieName = "USERID";
public static readonly CookieOptions cookieOptions = new CookieOptions()
{
Path = @"\",
HttpOnly = true,
IsEssential = true,
Expires = DateTime.Now.AddMonths(1) // TODO
};
public static WebApplication App { get => application; }
private static WadbContext context;
public static WadbContext GetContext()
{
var scope = application.Services.CreateAsyncScope();
var services = scope.ServiceProvider;
return services.GetRequiredService<WadbContext>();
}
private static void Main(string[] args)
{
SetUpWebApplication();
}
private static async Task SetUpWebApplication()
{
WebApplicationBuilder builder = WebApplication.CreateBuilder();
builder.Configuration.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Substring(0, Assembly.GetEntryAssembly().Location.IndexOf("bin\\"))));
builder.Configuration.AddJsonFile("appsettings.json").AddEnvironmentVariables();
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddDbContext<WadbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DBConnection")));
builder.Services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
WebApplication app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
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();
//app.UseSession(new SessionOptions()
//{
// IdleTimeout = TimeSpan.FromMinutes(5),
// Cookie = new CookieBuilder()
// {
// HttpOnly = true,
// IsEssential = true
// }
//});
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapGet("/getMapData", handler: WorldMapManager.GetMapData);
app.MapPost("/sendArmyData", handler: WorldMapManager.SendArmy);
app.MapPost("/restartMap", handler: WorldMapManager.RestartMap);
app.MapPost("/endTurn", handler: WorldMapManager.EndTurn);
app.UseRouting();
app.UseAuthorization();
app.UseCookiePolicy(new CookiePolicyOptions()
{
});
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
context = services.GetRequiredService<WadbContext>();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
app.MapRazorPages();
application = app;
app.Run();
}
}
}