mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using API.Data;
|
|
using API.Entities;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API
|
|
{
|
|
public class Program
|
|
{
|
|
private static readonly int HttpPort = 5000;
|
|
protected Program()
|
|
{
|
|
}
|
|
|
|
public static async Task Main(string[] args)
|
|
{
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
var services = scope.ServiceProvider;
|
|
|
|
try
|
|
{
|
|
var context = services.GetRequiredService<DataContext>();
|
|
var roleManager = services.GetRequiredService<RoleManager<AppRole>>();
|
|
// Apply all migrations on startup
|
|
await context.Database.MigrateAsync();
|
|
await Seed.SeedRoles(roleManager);
|
|
await Seed.SeedSettings(context);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var logger = services.GetRequiredService < ILogger<Program>>();
|
|
logger.LogError(ex, "An error occurred during migration");
|
|
}
|
|
|
|
await host.RunAsync();
|
|
}
|
|
|
|
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseKestrel((opts) =>
|
|
{
|
|
opts.ListenAnyIP(HttpPort, options =>
|
|
{
|
|
options.Protocols = HttpProtocols.Http1AndHttp2;
|
|
});
|
|
});
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
}
|
|
}
|