55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
|
using Asp.Versioning;
|
||
|
using OliverBooth.Common.Extensions;
|
||
|
using Serilog;
|
||
|
|
||
|
Log.Logger = new LoggerConfiguration()
|
||
|
.WriteTo.Console()
|
||
|
.WriteTo.File("logs/latest.log", rollingInterval: RollingInterval.Day)
|
||
|
#if DEBUG
|
||
|
.MinimumLevel.Debug()
|
||
|
#endif
|
||
|
.CreateLogger();
|
||
|
|
||
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||
|
builder.Configuration.AddTomlFile("data/config.toml", true, true);
|
||
|
builder.Logging.ClearProviders();
|
||
|
builder.Logging.AddSerilog();
|
||
|
|
||
|
builder.Services.AddCors(options =>
|
||
|
{
|
||
|
options.AddPolicy("localhost", policy => policy.WithOrigins("https://localhost:2845"));
|
||
|
options.AddPolicy("site", policy => policy.WithOrigins("https://oliverbooth.dev"));
|
||
|
});
|
||
|
|
||
|
builder.Services.AddCommonServices();
|
||
|
builder.Services.AddEndpointsApiExplorer();
|
||
|
builder.Services.AddSwaggerGen();
|
||
|
builder.Services.AddControllers();
|
||
|
builder.Services.AddRouting(options => options.LowercaseUrls = true);
|
||
|
builder.Services.AddApiVersioning(options =>
|
||
|
{
|
||
|
options.AssumeDefaultVersionWhenUnspecified = true;
|
||
|
options.DefaultApiVersion = new ApiVersion(1);
|
||
|
options.ReportApiVersions = true;
|
||
|
options.ApiVersionReader = new UrlSegmentApiVersionReader();
|
||
|
});
|
||
|
|
||
|
if (builder.Environment.IsProduction())
|
||
|
{
|
||
|
builder.WebHost.AddCertificateFromEnvironment(2844, 5048);
|
||
|
}
|
||
|
|
||
|
WebApplication app = builder.Build();
|
||
|
|
||
|
if (app.Environment.IsDevelopment())
|
||
|
{
|
||
|
app.UseSwagger();
|
||
|
app.UseSwaggerUI();
|
||
|
}
|
||
|
|
||
|
app.UseHttpsRedirection();
|
||
|
app.MapControllers();
|
||
|
app.UseCors(app.Environment.IsDevelopment() ? "localhost" : "site");
|
||
|
|
||
|
app.Run();
|