fix(proxy): honor forwarded headers from Caddy
All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m14s

Bump the application version to 1.2.2 and configure forwarded headers so
OpenAPI generates HTTPS URLs when TLS is terminated by Caddy.
This commit is contained in:
2026-07-26 20:40:35 +07:00
parent 4c271241d7
commit 8f0019592e
2 changed files with 18 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ public class ApplicationInfo
/// <summary>
/// The version of the application, to be defined and tagged
/// </summary>
public static readonly string Version = "1.2.1";
public static readonly string Version = "1.2.2";
/// <summary>
/// The commit hash of the application

View File

@@ -1,6 +1,7 @@
using CaddyManager.Api;
using CaddyManager.Components;
using Microsoft.AspNetCore.Components.Server;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.OpenApi;
using MudBlazor.Services;
using NetCore.AutoRegisterDi;
@@ -56,6 +57,19 @@ builder.Services.AddOpenApi(options =>
});
});
// Caddy terminates TLS and forwards plain HTTP, so without this the app thinks every request is
// http and the OpenAPI document advertises http:// server URLs, which the browser blocks as mixed
// content when the docs page itself was served over https
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto |
ForwardedHeaders.XForwardedHost;
// The proxy is another container on a Docker network, so its address is not known up front;
// this app is only ever meant to be reached through that proxy
options.KnownIPNetworks.Clear();
options.KnownProxies.Clear();
});
builder.Services.AddMudServices(config =>
{
config.SnackbarConfiguration.VisibleStateDuration = 4000;
@@ -65,6 +79,9 @@ builder.Services.AddMudServices(config =>
var app = builder.Build();
// Has to run before anything that reads the scheme, host or client address
app.UseForwardedHeaders();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{