2023-03-03 23:24:18 +03:30
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
using MTWireGuard.Middlewares;
|
2023-06-02 15:26:29 +03:30
|
|
|
using MTWireGuard.Application;
|
2024-01-25 20:40:43 +03:30
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
using MTWireGuard.Application.MinimalAPI;
|
2023-03-03 23:24:18 +03:30
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
2023-06-02 15:26:29 +03:30
|
|
|
builder.Services.AddApplicationServices();
|
2023-03-03 23:24:18 +03:30
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseExceptionHandler("/Error");
|
|
|
|
app.UseHsts();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
2023-06-02 15:26:29 +03:30
|
|
|
var serviceScope = app.Services.CreateScope().ServiceProvider;
|
2024-01-25 20:40:43 +03:30
|
|
|
|
|
|
|
// Validate Prerequisite
|
|
|
|
var validator = new SetupValidator(serviceScope);
|
|
|
|
await validator.Validate();
|
2023-06-02 15:26:29 +03:30
|
|
|
|
2023-03-03 23:24:18 +03:30
|
|
|
if (!app.Environment.IsDevelopment())
|
|
|
|
app.UseStaticFiles();
|
|
|
|
else
|
|
|
|
app.UseStaticFiles(new StaticFileOptions()
|
|
|
|
{
|
|
|
|
OnPrepareResponse = context =>
|
|
|
|
{
|
2024-01-25 20:40:43 +03:30
|
|
|
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.UseDependencyCheck();
|
2024-01-25 20:40:43 +03:30
|
|
|
app.UseClientReporting();
|
|
|
|
app.UseExceptionHandling();
|
2023-03-03 23:24:18 +03:30
|
|
|
//app.UseAntiForgery();
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
2024-01-25 20:40:43 +03:30
|
|
|
app.UseSession();
|
|
|
|
|
2023-03-03 23:24:18 +03:30
|
|
|
app.MapRazorPages();
|
|
|
|
|
2024-01-25 20:40:43 +03:30
|
|
|
app.
|
|
|
|
MapGroup("/api/").
|
|
|
|
MapGeneralApi();
|
|
|
|
|
|
|
|
app.UseCors(options =>
|
|
|
|
{
|
|
|
|
options.AllowAnyHeader();
|
|
|
|
options.AllowAnyMethod();
|
|
|
|
options.AllowAnyOrigin();
|
|
|
|
});
|
|
|
|
|
|
|
|
app.Run();
|