-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
135 lines (102 loc) · 3.86 KB
/
Copy pathProgram.cs
File metadata and controls
135 lines (102 loc) · 3.86 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
// should remove this, and switch to et 6
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders;
using Areas.Identity;
using MudBlazor;
using MudBlazor.Services;
using Embyte.Modules.Logging;
using Embyte.Modules.Middleware;
using Embyte.Modules.Db;
using Embyte.Data;
using Embyte.Data.Storage;
using Embyte.Modules.Product;
using Microsoft.AspNetCore.Hosting.StaticWebAssets;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("config/appsettings.json");
builder.Configuration.AddJsonFile("config/appsettings.Development.json");
// LOGGER
// USER
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
builder.Services.AddMudServices();
builder.Services.AddMudServices(config =>
{
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomLeft;
config.SnackbarConfiguration.PreventDuplicates = false;
config.SnackbarConfiguration.NewestOnTop = false;
config.SnackbarConfiguration.ShowCloseIcon = true;
config.SnackbarConfiguration.VisibleStateDuration = 8000;
config.SnackbarConfiguration.HideTransitionDuration = 500;
config.SnackbarConfiguration.ShowTransitionDuration = 500;
config.SnackbarConfiguration.SnackbarVariant = Variant.Filled;
});
// API
builder.Services.AddControllersWithViews(options =>
{
options.Conventions.Add(new RoutePrefixConvention("api"));
}).AddControllersAsServices();
// CONSTR
#if DEBUG
string ConnectionString = builder.Configuration["Database:ConnectionStringDevelopment"]!;
#else
string ConnectionString = builder.Configuration["Database:ConnectionStringProduction"]!;
Console.WriteLine($"Using connection string 2 : {ConnectionString}");
//Environment.SetEnvironmentVariable("Embyte_Database_ConnectionStringProduction", ConnectionString, EnvironmentVariableTarget.Process);
#endif
// DB TESTING
#if DEBUG
var con = new EmbyteDbContext();
// string TestingTable = "WebsiteUsage";
//Log.Debug($"Existing Tables: {string.Join(", ", DbHelper.GetExistingTables(con))}");
//Log.Debug($"Table {TestingTable} exists: {DbHelper.CheckTableExists(con, TestingTable)}");
//Log.Debug($"Number of entries in {TestingTable} {DbHelper.CheckNumberEntries(con, TestingTable)}");
#endif
// MODULES
builder.Services.AddSingleton<Constants>();
builder.Services.AddSingleton<FundamentalStorage>();
builder.Services.AddSingleton<MainStorage>();
builder.Services.AddScoped<LoggingMiddleware>();
builder.Services.AddScoped(provider =>
{
return new WebsiteUsageManager(new EmbyteDbContext());
});
builder.Services.AddScoped(provider =>
{
return new WebsiteInfoGetter(new EmbyteDbContext());
});
StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration);
var app = builder.Build();
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
// MIDDLEWARE
app.UseMiddleware<LoggingMiddleware>();
// HSTS
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Fundamental/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.UseRouting();
app.UseAuthorization();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(app.Environment.ContentRootPath, "static")),
RequestPath = "/static"
});
app.MapControllers();
app.MapBlazorHub();
app.MapFallbackToPage("/Fundamental/_Host");
app.Run();