-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (55 loc) · 2.03 KB
/
Program.cs
File metadata and controls
73 lines (55 loc) · 2.03 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
using Microsoft.EntityFrameworkCore;
using MyWebApplication.Data;
var builder = WebApplication.CreateBuilder(args);
// Read the connection string from the appsettings.json file
// var DB_CONN_STRING = builder.Configuration["PostgreSQL:ConnectionString"];
// Read environmental variable DB_STRING
var DB_CONN_STRING = Environment.GetEnvironmentVariable("DB_STRING");
builder.Services.AddDbContext<MyWebApplicationContext>(options =>
// options.UseSqlServer(builder.Configuration.GetConnectionString("MyWebApplicationContext") ?? throw new InvalidOperationException("Connection string 'MyWebApplicationContext' not found."))
options.UseNpgsql(DB_CONN_STRING ?? throw new InvalidOperationException("Connection string 'MyPostgreSQLContext' not found."))
);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Create or clear Temp folder
string tempFolderPath = "Temp";
if (!Directory.Exists(tempFolderPath))
{
Directory.CreateDirectory(tempFolderPath);
}
DirectoryInfo di = new DirectoryInfo(tempFolderPath);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/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.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
// options for websockets
var webSocketOptions = new WebSocketOptions
{
KeepAliveInterval = TimeSpan.FromMinutes(2)
};
app.UseWebSockets(webSocketOptions);
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}");
app.MapControllerRoute(
name: "socket",
pattern: "{controller=WebSocket}/{action=Index}/");
app.MapControllerRoute(
name: "upload",
pattern: "{controller=Upload}/{action=Index}/");
app.MapControllerRoute(
name: "upload",
pattern: "{controller=Board}/{action=Index}/");
app.Run();