using Hutopy.Application; using Hutopy.Infrastructure; using Hutopy.Infrastructure.Data; using Hutopy.Web; using Azure.Identity; using Microsoft.AspNetCore.HttpOverrides; var builder = WebApplication.CreateBuilder(args); if (!builder.Environment.IsDevelopment()) { var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri") ?? ""); builder.Configuration.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential()); } builder.Services.AddCors(options => { options.AddPolicy("AllowAll", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); options.AddPolicy("AllowHutopyUi", builder => { builder.WithOrigins("https://zealous-bay-08204590f.5.azurestaticapps.net") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); options.AddPolicy("AllowHutopyUiPreview", builder => { builder.WithOrigins("https://zealous-bay-08204590f-preview.eastus2.5.azurestaticapps.net") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); }); // Add services to the container. builder.Services.AddKeyVaultIfConfigured(builder.Configuration); builder.Services.AddApplicationServices(); builder.Services.AddInfrastructureServices(builder.Configuration); builder.Services.AddWebServices(); builder.Services.AddAuthorizationAndAuthentication(builder.Configuration); builder.Services.AddControllers(); var app = builder.Build(); app.UseForwardedHeaders( new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedProto } ); app.UseCors("AllowAll"); app.UseCors("AllowHutopyUi"); app.UseCors("AllowHutopyUiPreview"); app.UseAuthentication(); app.UseAuthorization(); // Initialize and seed the db. await app.InitialiseDatabaseAsync(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { // 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.UseHealthChecks("/health"); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSwaggerUi(settings => { settings.Path = "/api"; settings.DocumentPath = "/api/specification.json"; }); app.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); app.MapFallbackToFile("index.html"); app.UseExceptionHandler(options => { }); app.Map("/", () => Results.Redirect("/api")); app.MapEndpoints(); app.Run(); public abstract partial class Program { }