techgarage-ir.MTWireGuard/UI/Program.cs

84 lines
2.3 KiB
C#
Raw Normal View History

2023-06-02 15:26:29 +03:30
using MTWireGuard.Application;
using MTWireGuard.Application.MinimalAPI;
2024-11-08 19:31:21 +03:30
using MTWireGuard.Middlewares;
using Serilog;
2024-11-08 19:31:21 +03:30
using Serilog.Ui.Web.Extensions;
internal class Program
{
public static bool isValid { get; private set; }
public static string validationMessage { get; private set; }
2023-03-03 23:24:18 +03:30
private static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddExceptionHandler<ExceptionHandler>();
builder.Services.AddProblemDetails();
builder.Services.AddApplicationServices();
2023-03-03 23:24:18 +03:30
builder.Host.UseSerilog(Helper.LoggerConfiguration());
2023-03-03 23:24:18 +03:30
var app = builder.Build();
2023-03-03 23:24:18 +03:30
app.UseHttpsRedirection();
2023-03-03 23:24:18 +03:30
var serviceScope = app.Services.CreateScope().ServiceProvider;
// Validate Prerequisite
var validator = new SetupValidator(serviceScope);
isValid = await validator.Validate();
2023-06-02 15:26:29 +03:30
if (!app.Environment.IsDevelopment())
2023-03-03 23:24:18 +03:30
{
app.UseStaticFiles();
app.UseHsts();
2023-03-03 23:24:18 +03:30
}
else
app.UseStaticFiles(new StaticFileOptions()
{
OnPrepareResponse = context =>
{
context.Context.Response.Headers.Append("Cache-Control", "no-cache, no-store");
context.Context.Response.Headers.Append("Expires", "-1");
}
});
2023-03-03 23:24:18 +03:30
app.UseExceptionHandler();
app.UseClientReporting();
//app.UseAntiForgery();
app.UseRouting();
2023-03-03 23:24:18 +03:30
app.UseAuthentication();
app.UseAuthorization();
2023-03-03 23:24:18 +03:30
app.UseSession();
2023-03-03 23:24:18 +03:30
app.MapRazorPages();
app.
MapGroup("/api/").
MapGeneralApi();
2023-03-03 23:24:18 +03:30
app.UseCors(options =>
{
options.AllowAnyHeader();
options.AllowAnyMethod();
options.AllowAnyOrigin();
});
app.UseSerilogRequestLogging();
app.UseSerilogUi(options =>
{
2024-11-08 19:31:21 +03:30
options.HideSerilogUiBrand();
options.InjectJavascript("/assets/js/serilogui.js");
2024-11-08 19:31:21 +03:30
options.WithRoutePrefix("Debug");
options.WithAuthenticationType(Serilog.Ui.Web.Models.AuthenticationType.Custom);
options.EnableAuthorizationOnAppRoutes();
});
app.Run();
}
}