aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-05-02 22:19:26 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-05-02 22:19:26 -0500
commitc7b7468622484afbd4afdb4448b72323d9fb2e32 (patch)
treea2266bd3b18d5597bc3f3c8b0913c17e456af26e /src
parent6da054aff05dd886af44310231574f5dcaef3305 (diff)
downloadslskd-c7b7468622484afbd4afdb4448b72323d9fb2e32.tar.gz
add X-URL-Base
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Program.cs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index afdf4ab3..e21bf52e 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -470,10 +470,11 @@ namespace slskd
private static IServiceCollection ConfigureAspDotNetServices(this IServiceCollection services)
{
services.AddCors(options => options.AddPolicy("AllowAll", builder => builder
+ .SetIsOriginAllowed((host) => true)
.AllowAnyHeader()
.AllowAnyMethod()
- .SetIsOriginAllowed((host) => true)
- .AllowCredentials()));
+ .AllowCredentials()
+ .WithExposedHeaders("X-URL-Base")));
var jwtSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(OptionsAtStartup.Web.Authentication.Jwt.Key));
@@ -603,6 +604,19 @@ namespace slskd
urlBase = urlBase.StartsWith("/") ? urlBase : "/" + urlBase;
app.UsePathBase(urlBase);
+ app.Use((context, next) =>
+ {
+ context.Response.OnStarting(() =>
+ {
+ // the UI needs to be aware of what the URL base is,
+ // so that react-router can use explicit paths.
+ context.Response.Headers.Add("X-URL-Base", urlBase);
+ return Task.CompletedTask;
+ });
+
+ return next();
+ });
+
Log.Information("Using base url {UrlBase}", urlBase);
// remove any errant double forward slashes which may have been introduced by manipulating the path base