Refactored startup. Removed unused usings. Improved nuget package building. Switched to yaml for configuration. Moved asset files. Set correct context type for oauth2 pages. Updated versions
This commit is contained in:
@@ -1,24 +1,45 @@
|
||||
using MoonCore.Helpers;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Moonlight.ApiServer.Configuration;
|
||||
|
||||
public class AppConfiguration
|
||||
public record AppConfiguration
|
||||
{
|
||||
[YamlMember(Description = "The public url your instance should be accessible through")]
|
||||
public string PublicUrl { get; set; } = "http://localhost:5165";
|
||||
|
||||
[YamlMember(Description = "The credentials of the postgres which moonlight should use")]
|
||||
public DatabaseConfig Database { get; set; } = new();
|
||||
|
||||
[YamlMember(Description = "Settings regarding authentication")]
|
||||
public AuthenticationConfig Authentication { get; set; } = new();
|
||||
|
||||
[YamlMember(Description = "These options are only meant for development purposes")]
|
||||
public DevelopmentConfig Development { get; set; } = new();
|
||||
public ClientConfig Client { get; set; } = new();
|
||||
public FrontendData Frontend { get; set; } = new();
|
||||
public KestrelConfig Kestrel { get; set; } = new();
|
||||
public MetricsData Metrics { get; set; } = new();
|
||||
|
||||
public class ClientConfig
|
||||
public static AppConfiguration CreateEmpty()
|
||||
{
|
||||
public bool Enable { get; set; } = true;
|
||||
return new AppConfiguration()
|
||||
{
|
||||
// Set arrays as empty here
|
||||
|
||||
Kestrel = new()
|
||||
{
|
||||
AllowedOrigins = []
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public record FrontendData
|
||||
{
|
||||
[YamlMember(Description = "Enable the hosting of the frontend. Disable this if you only want to run the api server")]
|
||||
public bool EnableHosting { get; set; } = true;
|
||||
}
|
||||
|
||||
public class DatabaseConfig
|
||||
public record DatabaseConfig
|
||||
{
|
||||
public string Host { get; set; } = "your-database-host.name";
|
||||
public int Port { get; set; } = 5432;
|
||||
@@ -29,15 +50,19 @@ public class AppConfiguration
|
||||
public string Database { get; set; } = "db_name";
|
||||
}
|
||||
|
||||
public class AuthenticationConfig
|
||||
public record AuthenticationConfig
|
||||
{
|
||||
[YamlMember(Description = "The secret token to use for creating jwts and encrypting things. This needs to be at least 32 characters long")]
|
||||
public string Secret { get; set; } = Formatter.GenerateString(32);
|
||||
|
||||
[YamlMember(Description = "The lifespan of generated user tokens in hours")]
|
||||
public int TokenDuration { get; set; } = 24 * 10;
|
||||
|
||||
[YamlMember(Description = "This enables the use of the local oauth2 provider, so moonlight will use itself as an oauth2 provider")]
|
||||
public bool EnableLocalOAuth2 { get; set; } = true;
|
||||
public OAuth2Data OAuth2 { get; set; } = new();
|
||||
|
||||
public class OAuth2Data
|
||||
public record OAuth2Data
|
||||
{
|
||||
public string Secret { get; set; } = Formatter.GenerateString(32);
|
||||
public string ClientId { get; set; } = Formatter.GenerateString(8);
|
||||
@@ -46,24 +71,32 @@ public class AppConfiguration
|
||||
public string? AccessEndpoint { get; set; }
|
||||
public string? AuthorizationRedirect { get; set; }
|
||||
|
||||
[YamlMember(Description = "This specifies if the first registered user will become an admin automatically. This only works when using local oauth2")]
|
||||
public bool FirstUserAdmin { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class DevelopmentConfig
|
||||
public record DevelopmentConfig
|
||||
{
|
||||
[YamlMember(Description = "This toggles the availability of the api docs via /api/swagger")]
|
||||
public bool EnableApiDocs { get; set; } = false;
|
||||
}
|
||||
|
||||
public class KestrelConfig
|
||||
public record KestrelConfig
|
||||
{
|
||||
[YamlMember(Description = "The upload limit in megabytes for the api server")]
|
||||
public int UploadLimit { get; set; } = 100;
|
||||
public string AllowedOrigins { get; set; } = "*";
|
||||
|
||||
[YamlMember(Description = "The allowed origins for the api server. Use * to allow all origins (which is not advised)")]
|
||||
public string[] AllowedOrigins { get; set; } = ["*"];
|
||||
}
|
||||
|
||||
public class MetricsData
|
||||
public record MetricsData
|
||||
{
|
||||
[YamlMember(Description = "This enables the collecting of metrics and allows access to the /metrics endpoint")]
|
||||
public bool Enable { get; set; } = false;
|
||||
|
||||
[YamlMember(Description = "The interval in which metrics are created, specified in seconds")]
|
||||
public int Interval { get; set; } = 15;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user