Base Url Support (#642)
* Added base url config * UI side is not working * Working base url more * Attempt to get UI to work with base url * Implemented the ability to set the Base URL for the app * Hooked in Base URL as a managed setting * Ensure we always start with / for base url * Removed default base href from debug builds. Cleaned up an issue with base url migration. * Fixed an issue with our BaseURL migration
This commit is contained in:
parent
56239ee0a7
commit
27aaa040c4
14 changed files with 126 additions and 10 deletions
|
@ -8,7 +8,7 @@ namespace Kavita.Common
|
|||
{
|
||||
public static class Configuration
|
||||
{
|
||||
private static readonly string AppSettingsFilename = GetAppSettingFilename();
|
||||
private static string AppSettingsFilename = GetAppSettingFilename();
|
||||
public static string Branch
|
||||
{
|
||||
get => GetBranch(GetAppSettingFilename());
|
||||
|
@ -33,6 +33,12 @@ namespace Kavita.Common
|
|||
set => SetLogLevel(GetAppSettingFilename(), value);
|
||||
}
|
||||
|
||||
public static string BaseUrl
|
||||
{
|
||||
get => GetBaseUrl(GetAppSettingFilename());
|
||||
set => SetBaseUrl(GetAppSettingFilename(), value);
|
||||
}
|
||||
|
||||
private static string GetAppSettingFilename()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(AppSettingsFilename))
|
||||
|
@ -151,6 +157,55 @@ namespace Kavita.Common
|
|||
|
||||
#endregion
|
||||
|
||||
#region BaseUrl
|
||||
private static string GetBaseUrl(string filePath)
|
||||
{
|
||||
if (new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker)
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(filePath);
|
||||
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
|
||||
const string key = "BaseUrl";
|
||||
|
||||
if (jsonObj.TryGetProperty(key, out JsonElement tokenElement))
|
||||
{
|
||||
return tokenElement.GetString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error reading app settings: " + ex.Message);
|
||||
}
|
||||
|
||||
return "/";
|
||||
}
|
||||
|
||||
private static void SetBaseUrl(string filePath, string value)
|
||||
{
|
||||
if (new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var currentBaseUrl = GetBaseUrl(filePath);
|
||||
var json = File.ReadAllText(filePath);
|
||||
if (!json.Contains("BaseUrl"))
|
||||
{
|
||||
var lastBracket = json.LastIndexOf("}", StringComparison.Ordinal) - 1;
|
||||
json = (json.Substring(0, lastBracket) + (",\n \"BaseUrl\": " + currentBaseUrl) + "}");
|
||||
}
|
||||
else
|
||||
{
|
||||
json = json.Replace("\"BaseUrl\": " + currentBaseUrl, "\"BaseUrl\": " + value);
|
||||
}
|
||||
File.WriteAllText(filePath, json);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region LogLevel
|
||||
|
||||
private static void SetLogLevel(string filePath, string logLevel)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue