Multi-stage build: node builds the SPA, dotnet publishes the API, the runtime image serves the SPA from wwwroot/ and exposes /health. Frontend Supabase URL + publishable key are baked in at build time; DB conn string and Supabase JWKS metadata come from Coolify env vars. VITE_API_URL empty means same-origin, so the browser hits /api/todos on the same host that serves the SPA.
63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using Backend.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddDbContext<AppDbContext>(options =>
|
|
options.UseNpgsql(builder.Configuration.GetConnectionString("Postgres")));
|
|
|
|
const string DevCorsPolicy = "DevCors";
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(DevCorsPolicy, policy => policy
|
|
.WithOrigins("http://localhost:5173")
|
|
.AllowAnyHeader()
|
|
.WithMethods("GET", "POST", "PATCH", "DELETE"));
|
|
});
|
|
|
|
builder.Services
|
|
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
.AddJwtBearer(options =>
|
|
{
|
|
options.MetadataAddress = builder.Configuration["Supabase:MetadataAddress"]
|
|
?? throw new InvalidOperationException("Supabase:MetadataAddress not configured");
|
|
options.RequireHttpsMetadata = true;
|
|
options.MapInboundClaims = false;
|
|
options.TokenValidationParameters = new TokenValidationParameters
|
|
{
|
|
ValidateIssuer = true,
|
|
ValidIssuer = builder.Configuration["Supabase:Issuer"],
|
|
ValidateAudience = true,
|
|
ValidAudience = builder.Configuration["Supabase:Audience"],
|
|
ValidateIssuerSigningKey = true,
|
|
ValidateLifetime = true,
|
|
ClockSkew = TimeSpan.FromSeconds(30),
|
|
NameClaimType = "sub"
|
|
};
|
|
});
|
|
|
|
builder.Services.AddAuthorization();
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
var app = builder.Build();
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseCors(DevCorsPolicy);
|
|
}
|
|
|
|
app.UseDefaultFiles();
|
|
app.UseStaticFiles();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
app.MapGet("/health", () => Results.Ok(new { status = "ok" }));
|
|
app.MapFallbackToFile("index.html");
|
|
|
|
app.Run();
|