55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moonlight.Api;
|
|
using MoonlightServers.Api.Admin.Nodes;
|
|
using MoonlightServers.Api.Admin.Templates;
|
|
using MoonlightServers.Api.Infrastructure.Configuration;
|
|
using MoonlightServers.Api.Infrastructure.Database;
|
|
using MoonlightServers.Api.Infrastructure.Implementations.NodeToken;
|
|
using MoonlightServers.Shared;
|
|
using SimplePlugin.Abstractions;
|
|
|
|
namespace MoonlightServers.Api;
|
|
|
|
[PluginModule]
|
|
public class Startup : MoonlightPlugin
|
|
{
|
|
public override void PreBuild(WebApplicationBuilder builder)
|
|
{
|
|
builder.Services.AddControllers()
|
|
.AddApplicationPart(typeof(Startup).Assembly)
|
|
.AddJsonOptions(options =>
|
|
{
|
|
options.JsonSerializerOptions.TypeInfoResolverChain.Add(SerializationContext.Default);
|
|
});
|
|
|
|
builder.Services.AddScoped(typeof(DatabaseRepository<>));
|
|
|
|
builder.Services.AddDbContext<DataContext>();
|
|
builder.Services.AddHostedService<DbMigrationService>();
|
|
|
|
builder.Services.AddScoped<TemplateTransferService>();
|
|
builder.Services.AddScoped<PterodactylEggImportService>();
|
|
builder.Services.AddScoped<PelicanEggImportService>();
|
|
|
|
builder.Services.AddSingleton<NodeService>();
|
|
|
|
var nodeTokenOptions = new NodeTokenOptions();
|
|
builder.Configuration.Bind("Moonlight:Servers:NodeToken", nodeTokenOptions);
|
|
|
|
builder.Services
|
|
.AddAuthentication()
|
|
.AddScheme<NodeTokenSchemeOptions, NodeTokenSchemeHandler>(NodeTokenSchemeHandler.SchemeName, options =>
|
|
{
|
|
options.LookupCacheL1Expiry = nodeTokenOptions.LookupCacheL1Expiry;
|
|
options.LookupCacheL2Expiry = nodeTokenOptions.LookupCacheL2Expiry;
|
|
});
|
|
|
|
builder.Logging.AddFilter(
|
|
"MoonlightServers.Api.Infrastructure.Implementations.NodeToken.NodeTokenSchemeHandler",
|
|
LogLevel.Warning
|
|
);
|
|
}
|
|
} |