95 lines
2.5 KiB
C#
95 lines
2.5 KiB
C#
using Hutopy.Application;
|
|
using Hutopy.Domain.Interfaces;
|
|
using Hutopy.Infrastructure;
|
|
using Hutopy.Infrastructure.Data;
|
|
using Hutopy.Infrastructure.Services;
|
|
using Hutopy.Web;
|
|
using Azure.Identity;
|
|
|
|
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.AddScoped<IUserService, UserService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseCors("AllowAll");
|
|
app.UseCors("AllowHutopyUi");
|
|
app.UseCors("AllowHutopyUiPreview");
|
|
|
|
// 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.MapRazorPages();
|
|
|
|
app.MapFallbackToFile("index.html");
|
|
|
|
app.UseExceptionHandler(options => { });
|
|
|
|
app.Map("/", () => Results.Redirect("/api"));
|
|
|
|
app.MapEndpoints();
|
|
|
|
app.Run();
|
|
|
|
public abstract partial class Program { }
|