Files
sanstudent/Api/Program.cs
aherman-san b8f03bf6d3
All checks were successful
SanStudent Multi-Project Deployment / deploy-api (push) Successful in 41s
SanStudent Multi-Project Deployment / deploy-frontadmin (push) Successful in 41s
SanStudent Multi-Project Deployment / deploy-frontstudent (push) Successful in 40s
Add project
2026-03-07 11:14:26 +01:00

62 lines
1.8 KiB
C#

using Api.Database;
using Api.Services.Implementation;
using Api.Services.Interfaces;
using Microsoft.EntityFrameworkCore;
using Scalar.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowBlazorFrontends",
policy =>
{
policy.WithOrigins("https://sanstudent.aherman.eu",
"https://sanstudent.eu",
"https://www.sanstudent.eu",
"https://localhost:7001",
"https://localhost:7000"
)
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Services.AddDbContext<SanStudentContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
});
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = builder.Configuration.GetConnectionString("RedisCache");
options.InstanceName = "SanStudentApi_";
});
builder.Services.AddScoped<ISpecializationService, SpecializationService>();
builder.Services.AddScoped<ISubjectService, SubjectService>();
builder.Services.AddScoped<ISeasonService, SeasonService>();
builder.Services.AddControllers();
builder.Services.AddOpenApi();
var app = builder.Build();
app.UseCors("AllowBlazorFrontends");
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapScalarApiReference(options =>
{
options.Title = "SanStudent API";
options.Theme = ScalarTheme.BluePlanet;
options.DefaultHttpClient = new(ScalarTarget.CSharp, ScalarClient.HttpClient);
options.CustomCss = "";
options.ShowSidebar = true;
});
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();