techgarage-ir.MTWireGuard/UI/Program.cs

66 lines
1.4 KiB
C#
Raw Normal View History

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;
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;
// 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 =>
{
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();
app.UseClientReporting();
app.UseExceptionHandling();
2023-03-03 23:24:18 +03:30
//app.UseAntiForgery();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
2023-03-03 23:24:18 +03:30
app.MapRazorPages();
app.
MapGroup("/api/").
MapGeneralApi();
app.UseCors(options =>
{
options.AllowAnyHeader();
options.AllowAnyMethod();
options.AllowAnyOrigin();
});
app.Run();