diff --git a/server/RdtClient.Service/Middleware/BaseHrefMiddleware.cs b/server/RdtClient.Service/Middleware/BaseHrefMiddleware.cs
index 6477c49..54b5bba 100644
--- a/server/RdtClient.Service/Middleware/BaseHrefMiddleware.cs
+++ b/server/RdtClient.Service/Middleware/BaseHrefMiddleware.cs
@@ -1,19 +1,20 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http;
-using RdtClient.Data.Models.Internal;
namespace RdtClient.Service.Middleware;
public class BaseHrefMiddleware
{
private readonly RequestDelegate _next;
+ private readonly String _basePath;
- public BaseHrefMiddleware(RequestDelegate next)
+ public BaseHrefMiddleware(RequestDelegate next, String basePath)
{
_next = next;
+ _basePath = $"/{basePath.TrimStart('/').TrimEnd('/')}/";
}
- public async Task InvokeAsync(HttpContext context, AppSettings appSettings)
+ public async Task InvokeAsync(HttpContext context)
{
var originalBody = context.Response.Body;
@@ -32,12 +33,10 @@ public class BaseHrefMiddleware
// ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
if (context.Response.ContentType?.Contains("text/html") == true)
{
- var basePath = $"/{appSettings.BasePath!.TrimStart('/').TrimEnd('/')}/";
+ responseBody = Regex.Replace(responseBody, @")", $"$1{basePath}$2$3");
- responseBody = Regex.Replace(responseBody, "()", $"$1{basePath}$2$3");
+ responseBody = Regex.Replace(responseBody, "()", $"$1{_basePath}$2$3");
+ responseBody = Regex.Replace(responseBody, "()", $"$1{_basePath}$2$3");
context.Response.Headers.Remove("Content-Length");
await context.Response.WriteAsync(responseBody);
diff --git a/server/RdtClient.Web/Program.cs b/server/RdtClient.Web/Program.cs
index 585a52b..cc69adb 100644
--- a/server/RdtClient.Web/Program.cs
+++ b/server/RdtClient.Web/Program.cs
@@ -164,9 +164,11 @@ try
}
});
- if (!String.IsNullOrWhiteSpace(appSettings.BasePath))
+ var basePath = !String.IsNullOrWhiteSpace(appSettings.BasePath) ? appSettings.BasePath : !String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("BASE_PATH")) ? Environment.GetEnvironmentVariable("BASE_PATH") : null;
+
+ if (basePath != null)
{
- app.UseMiddleware();
+ app.UseMiddleware(basePath);
}
app.UseMiddleware();