Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
36 lines
No EOL
1 KiB
C#
36 lines
No EOL
1 KiB
C#
using AutoMapper;
|
|
using LANCommander.Server.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LANCommander.Server.Endpoints;
|
|
|
|
public static class SettingsEndpoints
|
|
{
|
|
public static void MapSettingsEndpoints(this IEndpointRouteBuilder routes)
|
|
{
|
|
var group = routes.MapGroup("/api/Settings");
|
|
|
|
group.MapGet("/", GetAsync);
|
|
}
|
|
|
|
public static async Task<IResult> GetAsync(
|
|
[FromServices] SettingsProvider<Settings.Settings> settingsProvider,
|
|
[FromServices] ServerService serverService,
|
|
[FromServices] IMapper mapper)
|
|
{
|
|
var clientSettings = new
|
|
{
|
|
IPXRelay = new
|
|
{
|
|
Host = settingsProvider.CurrentValue.Server.IPXRelay.Host,
|
|
Port = settingsProvider.CurrentValue.Server.IPXRelay.Port,
|
|
},
|
|
Library = new
|
|
{
|
|
EnableUserLibraries = settingsProvider.CurrentValue.Server.Library.EnableUserLibraries,
|
|
}
|
|
};
|
|
|
|
return TypedResults.Ok(clientSettings);
|
|
}
|
|
} |