You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
using Models;
|
|
using Serilog;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
//TODO Make this configurable from appsettings
|
|
Log.Logger = new LoggerConfiguration()
|
|
.MinimumLevel.Debug()
|
|
.WriteTo.Console()
|
|
//.WriteTo.File("logs/portfolioportal.txt", rollingInterval: RollingInterval.Day)
|
|
.CreateLogger();
|
|
Log.Information("Starting Portfolio Portal ASP.NET Core Backend");
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddControllers()
|
|
.AddNewtonsoftJson();
|
|
builder.Logging.AddSerilog();
|
|
|
|
var conString = builder.Configuration.GetConnectionString("PortfolioPortalConnection");
|
|
Log.Information($"Connection string: {conString}");
|
|
|
|
builder.Services.AddDbContext<PortfolioPortalDbContext>(options =>
|
|
options.UseSqlServer(conString)
|
|
.EnableSensitiveDataLogging());
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
// Custom JWT handling with Ed25519 validation
|
|
// Just add [Authorize(Roles = )] to require validation on a component
|
|
app.UseMiddleware<JwtAuthenticationMiddleware>();
|
|
|
|
// If this is the production build make sure we're always using HTTPS
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
// If an unhandled exception is encountered redirect to Error endpoint
|
|
//TODO Create an error endpoint
|
|
app.UseExceptionHandler("/Error");
|
|
app.UseHsts();
|
|
}
|
|
else
|
|
{
|
|
// Generates a rich error page with detailed information such as the exception type, message, stack trace, request details, and more
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.Run();
|
|
|