From c7b7468622484afbd4afdb4448b72323d9fb2e32 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 2 May 2022 22:19:26 -0500 Subject: add X-URL-Base --- src/slskd/Program.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/slskd/Program.cs') 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 -- cgit v1.2.3