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
|
@ -85,6 +85,17 @@ namespace API.Controllers
|
|||
_unitOfWork.SettingsRepository.Update(setting);
|
||||
}
|
||||
|
||||
if (setting.Key == ServerSettingKey.BaseUrl && updateSettingsDto.BaseUrl + string.Empty != setting.Value)
|
||||
{
|
||||
var path = !updateSettingsDto.BaseUrl.StartsWith("/")
|
||||
? $"/{updateSettingsDto.BaseUrl}"
|
||||
: updateSettingsDto.BaseUrl;
|
||||
setting.Value = path;
|
||||
// BaseUrl is managed in appSetting.json
|
||||
Configuration.BaseUrl = updateSettingsDto.BaseUrl;
|
||||
_unitOfWork.SettingsRepository.Update(setting);
|
||||
}
|
||||
|
||||
if (setting.Key == ServerSettingKey.LoggingLevel && updateSettingsDto.LoggingLevel + string.Empty != setting.Value)
|
||||
{
|
||||
setting.Value = updateSettingsDto.LoggingLevel + string.Empty;
|
||||
|
|
|
@ -26,5 +26,9 @@
|
|||
/// Enables Authentication on the server. Defaults to true.
|
||||
/// </summary>
|
||||
public bool EnableAuthentication { get; set; }
|
||||
/// <summary>
|
||||
/// Base Url for the kavita. Defaults to "/". Managed in appsettings.json.Requires restart to take effect.
|
||||
/// </summary>
|
||||
public string BaseUrl { get; set; } = "/";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ namespace API.Data
|
|||
new () {Key = ServerSettingKey.AllowStatCollection, Value = "true"},
|
||||
new () {Key = ServerSettingKey.EnableOpds, Value = "false"},
|
||||
new () {Key = ServerSettingKey.EnableAuthentication, Value = "true"},
|
||||
new () {Key = ServerSettingKey.BaseUrl, Value = ""},// Not used from DB, but DB is sync with appSettings.json
|
||||
};
|
||||
|
||||
foreach (var defaultSetting in defaultSettings)
|
||||
|
@ -63,11 +64,20 @@ namespace API.Data
|
|||
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
if (string.IsNullOrEmpty(Configuration.BaseUrl))
|
||||
{
|
||||
Configuration.BaseUrl = "/";
|
||||
}
|
||||
|
||||
// Port and LoggingLevel are managed in appSettings.json. Update the DB values to match
|
||||
context.ServerSetting.First(s => s.Key == ServerSettingKey.Port).Value =
|
||||
Configuration.Port + string.Empty;
|
||||
context.ServerSetting.First(s => s.Key == ServerSettingKey.LoggingLevel).Value =
|
||||
Configuration.LogLevel + string.Empty;
|
||||
context.ServerSetting.First(s => s.Key == ServerSettingKey.BaseUrl).Value =
|
||||
Configuration.BaseUrl;
|
||||
|
||||
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ namespace API.Entities.Enums
|
|||
[Description("EnableOpds")]
|
||||
EnableOpds = 7,
|
||||
[Description("EnableAuthentication")]
|
||||
EnableAuthentication = 8
|
||||
EnableAuthentication = 8,
|
||||
[Description("BaseUrl")]
|
||||
BaseUrl = 9
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ namespace API.Helpers.Converters
|
|||
case ServerSettingKey.EnableAuthentication:
|
||||
destination.EnableAuthentication = bool.Parse(row.Value);
|
||||
break;
|
||||
case ServerSettingKey.BaseUrl:
|
||||
destination.BaseUrl = row.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -160,11 +160,23 @@ namespace API
|
|||
|
||||
app.UseDefaultFiles();
|
||||
|
||||
if (!string.IsNullOrEmpty(Configuration.BaseUrl))
|
||||
{
|
||||
var path = !Configuration.BaseUrl.StartsWith("/")
|
||||
? $"/{Configuration.BaseUrl}"
|
||||
: Configuration.BaseUrl;
|
||||
app.UsePathBase(path);
|
||||
Console.WriteLine("Starting with base url as " + path);
|
||||
}
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
ContentTypeProvider = new FileExtensionContentTypeProvider()
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
context.Response.GetTypedHeaders().CacheControl =
|
||||
|
|
|
@ -18,5 +18,7 @@
|
|||
"MaxRollingFiles": 5
|
||||
}
|
||||
},
|
||||
"Port": 5000
|
||||
"Port": 5000,
|
||||
"BaseUrl": "/"
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue