7f78545a02
Content API: - Enabling CORS for access from Blazor app Web Server: - Content API URL environment config - Web Audio API JS Interop layer in TypeScript - HttpClient configs Web Client: - Audio Tack player controls - Audio Player example page - Audio Interop Service Layer - Named HttpClients
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using DeepDrftContent;
|
|
using DeepDrftContent.FileDatabase.Services;
|
|
using DeepDrftContent.Middleware;
|
|
using DeepDrftContent.Models;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
await Startup.ConfigureDomainServices(builder);
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
builder.Services.AddOpenApi();
|
|
|
|
// Add CORS policy using configured origins
|
|
var corsSettings = builder.Configuration.GetSection(nameof(CorsSettings)).Get<CorsSettings>();
|
|
if (corsSettings?.AllowedOrigins == null || corsSettings.AllowedOrigins.Length == 0)
|
|
{
|
|
throw new Exception("CorsSettings.AllowedOrigins configuration is required for CORS policy");
|
|
}
|
|
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("ContentApiPolicy", policy =>
|
|
{
|
|
policy.WithOrigins(corsSettings.AllowedOrigins)
|
|
.AllowAnyMethod()
|
|
.AllowAnyHeader()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
|
|
// Load API key configuration
|
|
builder.Configuration.AddJsonFile("environment/apikey.json", optional: false, reloadOnChange: true);
|
|
var apiKeySettings = builder.Configuration.GetSection(nameof(ApiKeySettings)).Get<ApiKeySettings>();
|
|
if (apiKeySettings is null) { throw new Exception("API key settings are not configured"); }
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
app.UseCors("ContentApiPolicy");
|
|
app.UseApiKeyAuthentication(apiKeySettings.ApiKey);
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run(); |