Add PublicUrl support for reverse proxy handling
Build and Push Docker Image / build-and-push (push) Successful in 20s
Build and Push Docker Image / build-and-push (push) Successful in 20s
Introduced a `PUBLIC_URL` environment variable to configure the public URL for OAuth callbacks and reverse proxy scenarios. Updated `Program.cs` to rewrite request scheme and host based on `PublicUrl`. Replaced `Microsoft.AspNetCore.Components.Authorization` with `Microsoft.AspNetCore.Components.Authentication`. Added `PublicUrl` to `appsettings.json` with a default empty value.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
using System.Data;
|
||||
using BirthList.Infrastructure.Persistence;
|
||||
using BirthList.Web.Authorization;
|
||||
using BirthList.Web.Components;
|
||||
using BirthList.Web.Components.Account;
|
||||
using BirthList.Web.Configuration;
|
||||
using BirthList.Web.Data;
|
||||
using BirthList.Web.Features.Registries;
|
||||
using BirthList.Web.Services;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
@@ -9,10 +13,6 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using BirthList.Web.Components;
|
||||
using BirthList.Web.Components.Account;
|
||||
using BirthList.Web.Data;
|
||||
using System.Data;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -159,6 +159,20 @@ else
|
||||
}
|
||||
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
var publicUrl = app.Configuration["PublicUrl"];
|
||||
if (!string.IsNullOrWhiteSpace(publicUrl) && Uri.TryCreate(publicUrl, UriKind.Absolute, out var publicUri))
|
||||
{
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
context.Request.Scheme = publicUri.Scheme;
|
||||
context.Request.Host = publicUri.IsDefaultPort
|
||||
? new Microsoft.AspNetCore.Http.HostString(publicUri.Host)
|
||||
: new Microsoft.AspNetCore.Http.HostString(publicUri.Host, publicUri.Port);
|
||||
await next();
|
||||
});
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
Reference in New Issue
Block a user