LANCommander/LANCommander.Server/Program.cs

89 lines
1.7 KiB
C#
Raw Normal View History

2024-08-04 18:44:33 -05:00
using LANCommander.Server.Services;
using Serilog;
2025-02-08 15:28:13 -06:00
using LANCommander.Server.Services.Models;
using LANCommander.Server.UI;
using LANCommander.Server.Startup;
var builder = WebApplication.CreateBuilder(args);
2025-02-08 15:28:13 -06:00
if (args.Contains("--debugger"))
2025-03-11 21:21:16 -05:00
builder.WaitForDebugger();
2025-02-08 15:28:13 -06:00
2025-03-07 20:44:32 -06:00
if (args.Contains("--docker"))
SettingService.WorkingDirectory = "/app/config";
2025-02-08 15:28:13 -06:00
builder.AddAsService();
builder.AddLogger();
Settings settings;
2025-03-11 21:21:16 -05:00
builder.AddSettings(out settings);
2025-03-11 21:21:16 -05:00
builder.AddRazor();
builder.AddSignalR();
builder.AddCors();
builder.AddControllers();
2025-02-08 15:28:13 -06:00
builder.ConfigureKestrel();
2025-03-11 21:21:16 -05:00
builder.ConfigureAuthentication(settings);
builder.AddIdentity(settings);
builder.AddHangfire();
2025-02-09 01:23:33 -06:00
builder.AddOpenApi();
builder.AddLANCommanderServices(settings);
builder.AddDatabase();
Log.Debug("Building Application");
var app = builder.Build();
2025-03-11 21:21:16 -05:00
app.UseDatabase(args);
app.UseCors("CorsPolicy");
2025-02-08 15:28:13 -06:00
app.UseHttpsRedirection();
2025-03-11 21:21:16 -05:00
app.UseMiddlewares();
2025-02-08 15:28:13 -06:00
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
Log.Debug("App has been run in a development environment");
app.UseMigrationsEndPoint();
}
else
{
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();
}
2025-03-11 21:21:16 -05:00
app.UseHangfire();
// app.UseHttpsRedirection();
app.UseStaticFiles();
2025-02-08 15:28:13 -06:00
app.UseCookiePolicy();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseAntiforgery();
2025-03-11 21:21:16 -05:00
app.UseSignalR();
2025-02-08 15:28:13 -06:00
app.UseStaticFiles();
app.MapScalar();
2025-03-11 21:21:16 -05:00
app.MapEndpoints();
2025-02-16 02:12:13 -06:00
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
2025-03-11 21:21:16 -05:00
app.PrepareDirectories();
2025-03-11 21:21:16 -05:00
await app.MigrateDatabaseAsync();
await app.StartServerProcessesAsync();
2025-03-11 21:21:16 -05:00
app.GenerateThumbnails();
2025-02-08 15:28:13 -06:00
app.Run();