aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server/Program.cs')
-rw-r--r--Jellyfin.Server/Program.cs70
1 files changed, 69 insertions, 1 deletions
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index e8bd0cd30..998f1125f 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -18,8 +18,10 @@ using Jellyfin.Drawing.Skia;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Model.Globalization;
+using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Extensions.Logging;
@@ -164,7 +166,24 @@ namespace Jellyfin.Server
appConfig);
try
{
- await appHost.InitAsync(new ServiceCollection()).ConfigureAwait(false);
+ ServiceCollection serviceCollection = new ServiceCollection();
+ await appHost.InitAsync(serviceCollection).ConfigureAwait(false);
+
+ var host = CreateWebHostBuilder(appHost, serviceCollection).Build();
+
+ // A bit hacky to re-use service provider since ASP.NET doesn't allow a custom service collection.
+ appHost.ServiceProvider = host.Services;
+ appHost.FindParts();
+
+ try
+ {
+ await host.StartAsync().ConfigureAwait(false);
+ }
+ catch
+ {
+ _logger.LogError("Kestrel failed to start! This is most likely due to an invalid address or port bind - correct your bind configuration in system.xml and try again.");
+ throw;
+ }
appHost.ImageProcessor.ImageEncoder = GetImageEncoder(appPaths, appHost.LocalizationManager);
@@ -196,6 +215,55 @@ namespace Jellyfin.Server
}
}
+ private static IWebHostBuilder CreateWebHostBuilder(ApplicationHost appHost, IServiceCollection serviceCollection)
+ {
+ return new WebHostBuilder()
+ .UseKestrel(options =>
+ {
+ var addresses = appHost.ServerConfigurationManager
+ .Configuration
+ .LocalNetworkAddresses
+ .Select(appHost.NormalizeConfiguredLocalAddress)
+ .Where(i => i != null)
+ .ToList();
+ if (addresses.Any())
+ {
+ foreach (var address in addresses)
+ {
+ _logger.LogInformation("Kestrel listening on {ipaddr}", address);
+ options.Listen(address, appHost.HttpPort);
+
+ if (appHost.EnableHttps && appHost.Certificate != null)
+ {
+ options.Listen(
+ address,
+ appHost.HttpsPort,
+ listenOptions => listenOptions.UseHttps(appHost.Certificate));
+ }
+ }
+ }
+ else
+ {
+ _logger.LogInformation("Kestrel listening on all interfaces");
+ options.ListenAnyIP(appHost.HttpPort);
+
+ if (appHost.EnableHttps && appHost.Certificate != null)
+ {
+ options.ListenAnyIP(
+ appHost.HttpsPort,
+ listenOptions => listenOptions.UseHttps(appHost.Certificate));
+ }
+ }
+ })
+ .UseContentRoot(appHost.ContentRoot)
+ .ConfigureServices(services =>
+ {
+ // Merge the external ServiceCollection into ASP.NET DI
+ services.TryAdd(serviceCollection);
+ })
+ .UseStartup<Startup>();
+ }
+
/// <summary>
/// Create the data, config and log paths from the variety of inputs(command line args,
/// environment variables) or decide on what default to use. For Windows it's %AppPath%