Base Url implementation (#1824)
* Base Url implementation * PR requested changes
This commit is contained in:
parent
74f62fd5e2
commit
2cff1bcebe
12 changed files with 134 additions and 9 deletions
|
|
@ -191,6 +191,7 @@ public class SettingsController : BaseApiController
|
|||
? $"{path}/"
|
||||
: path;
|
||||
setting.Value = path;
|
||||
Configuration.BaseUrl = updateSettingsDto.BaseUrl;
|
||||
_unitOfWork.SettingsRepository.Update(setting);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"TokenKey": "super secret unguessable key",
|
||||
"Port": 5000,
|
||||
"IpAddresses": ""
|
||||
"IpAddresses": "",
|
||||
"BaseUrl": "/"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"TokenKey": "super secret unguessable key",
|
||||
"Port": 5000,
|
||||
"IpAddresses": ""
|
||||
"IpAddresses": "",
|
||||
"BaseUrl": "/"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue