Base Url implementation (#1824)

* Base Url implementation

* PR requested changes
This commit is contained in:
Gazy Mahomar 2023-03-11 14:47:40 +01:00 committed by GitHub
parent 74f62fd5e2
commit 2cff1bcebe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 134 additions and 9 deletions

View file

@ -19,6 +19,7 @@ using API.Services.HostedServices;
using API.Services.Tasks;
using API.SignalR;
using Hangfire;
using HtmlAgilityPack;
using Kavita.Common;
using Kavita.Common.EnvironmentInfo;
using Microsoft.AspNetCore.Builder;
@ -277,6 +278,11 @@ public class Startup
app.UseForwardedHeaders();
var basePath = Configuration.BaseUrl;
app.UsePathBase(basePath);
UpdateBaseUrlInIndex(basePath);
app.UseRouting();
// Ordering is important. Cors, authentication, authorization
@ -351,6 +357,20 @@ public class Startup
}
Console.WriteLine($"Kavita - v{BuildInfo.Version}");
});
var _logger = serviceProvider.GetRequiredService<ILogger<Startup>>();
_logger.LogInformation("Starting with base url as {baseUrl}", basePath);
}
private static void UpdateBaseUrlInIndex(string baseUrl)
{
var htmlDoc = new HtmlDocument();
var indexHtmlPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html");
htmlDoc.Load(indexHtmlPath);
var baseNode = htmlDoc.DocumentNode.SelectSingleNode("/html/head/base");
baseNode.SetAttributeValue("href", baseUrl);
htmlDoc.Save(indexHtmlPath);
}
private static void OnShutdown()