Properly redirect healthcheck endpoint if using BaseUrl

This commit is contained in:
crobibero 2021-04-13 07:12:49 -06:00
parent 89ae336694
commit b11718a01d

View File

@ -45,6 +45,16 @@ namespace Jellyfin.Server.Middleware
var localPath = httpContext.Request.Path.ToString();
var baseUrlPrefix = serverConfigurationManager.GetNetworkConfiguration().BaseUrl;
if (!string.IsNullOrEmpty(baseUrlPrefix))
{
if (!localPath.StartsWith(baseUrlPrefix, StringComparison.OrdinalIgnoreCase)
&& localPath.EndsWith("/health", StringComparison.OrdinalIgnoreCase))
{
_logger.LogDebug("Redirecting /health check");
httpContext.Response.Redirect(baseUrlPrefix + "/health");
return;
}
if (string.Equals(localPath, baseUrlPrefix + "/", StringComparison.OrdinalIgnoreCase)
|| string.Equals(localPath, baseUrlPrefix, StringComparison.OrdinalIgnoreCase)
|| string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase)
@ -56,6 +66,7 @@ namespace Jellyfin.Server.Middleware
httpContext.Response.Redirect(baseUrlPrefix + "/" + _configuration[ConfigurationExtensions.DefaultRedirectKey]);
return;
}
}
await _next(httpContext).ConfigureAwait(false);
}