Implemented the ability to configure the default port for non-docker users. Docker users will always be 5000. (#280)

This commit is contained in:
Joseph Milazzo 2021-06-07 14:36:35 -05:00 committed by GitHub
parent 4606b54603
commit 5259a1484a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 7 deletions

View file

@ -8,6 +8,7 @@ using API.Entities.Enums;
using API.Extensions;
using API.Helpers.Converters;
using API.Interfaces;
using Kavita.Common;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
@ -34,7 +35,9 @@ namespace API.Controllers
[HttpGet("")]
public async Task<ActionResult<ServerSettingDto>> GetSettings()
{
return Ok(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync());
var settingsDto = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();
settingsDto.Port = Configuration.GetPort(Program.GetAppSettingFilename());
return Ok(settingsDto);
}
[Authorize(Policy = "RequireAdminRole")]
@ -76,7 +79,8 @@ namespace API.Controllers
if (setting.Key == ServerSettingKey.Port && updateSettingsDto.Port + "" != setting.Value)
{
setting.Value = updateSettingsDto.Port + "";
Environment.SetEnvironmentVariable("KAVITA_PORT", setting.Value);
// Port is managed in appSetting.json
Configuration.UpdatePort(Program.GetAppSettingFilename(), updateSettingsDto.Port);
_unitOfWork.SettingsRepository.Update(setting);
}

View file

@ -41,7 +41,7 @@ namespace API.Data
//new () {Key = ServerSettingKey.LoggingLevel, Value = "Information"},
new () {Key = ServerSettingKey.TaskBackup, Value = "weekly"},
new () {Key = ServerSettingKey.BackupDirectory, Value = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), "backups/"))},
new () {Key = ServerSettingKey.Port, Value = "5000"},
//new () {Key = ServerSettingKey.Port, Value = "5000"}, // TODO: Remove ServerSettingKey
};
foreach (var defaultSetting in defaultSettings)

View file

@ -20,13 +20,13 @@ namespace API
{
public class Program
{
private static readonly int HttpPort = 5000;
private static int HttpPort;
protected Program()
{
}
private static string GetAppSettingFilename()
public static string GetAppSettingFilename()
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var isDevelopment = environment == Environments.Development;
@ -46,6 +46,9 @@ namespace API
var base64 = Convert.ToBase64String(rBytes).Replace("/", "");
Configuration.UpdateJwtToken(GetAppSettingFilename(), base64);
}
// Get HttpPort from Config
HttpPort = Configuration.GetPort(GetAppSettingFilename());
var host = CreateHostBuilder(args).Build();

View file

@ -17,5 +17,6 @@
"FileSizeLimitBytes": 0,
"MaxRollingFiles": 0
}
}
},
"Port": 5000
}