Pārlūkot izejas kodu

Merge pull request #2636 from mark-monteiro/development-https

Use ASP.NET Core HTTPS Development Certificate
Bond-009 5 gadi atpakaļ
vecāks
revīzija
29539174a3

+ 10 - 5
Emby.Server.Implementations/ApplicationHost.cs

@@ -118,6 +118,11 @@ namespace Emby.Server.Implementations
     /// </summary>
     public abstract class ApplicationHost : IServerApplicationHost, IDisposable
     {
+        /// <summary>
+        /// The environment variable prefixes to log at server startup.
+        /// </summary>
+        private static readonly string[] _relevantEnvVarPrefixes = { "JELLYFIN_", "DOTNET_", "ASPNETCORE_" };
+
         private SqliteUserRepository _userRepository;
         private SqliteDisplayPreferencesRepository _displayPreferencesRepository;
 
@@ -889,18 +894,18 @@ namespace Emby.Server.Implementations
                 .GetCommandLineArgs()
                 .Distinct();
 
-            // Get all 'JELLYFIN_' prefixed environment variables
+            // Get all relevant environment variables
             var allEnvVars = Environment.GetEnvironmentVariables();
-            var jellyfinEnvVars = new Dictionary<object, object>();
+            var relevantEnvVars = new Dictionary<object, object>();
             foreach (var key in allEnvVars.Keys)
             {
-                if (key.ToString().StartsWith("JELLYFIN_", StringComparison.OrdinalIgnoreCase))
+                if (_relevantEnvVarPrefixes.Any(prefix => key.ToString().StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
                 {
-                    jellyfinEnvVars.Add(key, allEnvVars[key]);
+                    relevantEnvVars.Add(key, allEnvVars[key]);
                 }
             }
 
-            logger.LogInformation("Environment Variables: {EnvVars}", jellyfinEnvVars);
+            logger.LogInformation("Environment Variables: {EnvVars}", relevantEnvVars);
             logger.LogInformation("Arguments: {Args}", commandLineArgs);
             logger.LogInformation("Operating system: {OS}", OperatingSystem.Name);
             logger.LogInformation("Architecture: {Architecture}", RuntimeInformation.OSArchitecture);

+ 18 - 1
Jellyfin.Server/Program.cs

@@ -25,6 +25,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Logging.Abstractions;
 using Serilog;
@@ -259,7 +260,7 @@ namespace Jellyfin.Server
             IApplicationPaths appPaths)
         {
             return new WebHostBuilder()
-                .UseKestrel(options =>
+                .UseKestrel((builderContext, options) =>
                 {
                     var addresses = appHost.ServerConfigurationManager
                         .Configuration
@@ -282,6 +283,14 @@ namespace Jellyfin.Server
                                     listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
                                 });
                             }
+                            else if (builderContext.HostingEnvironment.IsDevelopment())
+                            {
+                                options.Listen(address, appHost.HttpsPort, listenOptions =>
+                                {
+                                    listenOptions.UseHttps();
+                                    listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
+                                });
+                            }
                         }
                     }
                     else
@@ -297,6 +306,14 @@ namespace Jellyfin.Server
                                 listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
                             });
                         }
+                        else if (builderContext.HostingEnvironment.IsDevelopment())
+                        {
+                            options.ListenAnyIP(appHost.HttpsPort, listenOptions =>
+                            {
+                                listenOptions.UseHttps();
+                                listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
+                            });
+                        }
                     }
                 })
                 .ConfigureAppConfiguration(config => config.ConfigureAppConfiguration(commandLineOpts, appPaths, startupConfig))

+ 8 - 2
Jellyfin.Server/Properties/launchSettings.json

@@ -1,11 +1,17 @@
 {
   "profiles": {
     "Jellyfin.Server": {
-      "commandName": "Project"
+      "commandName": "Project",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
     },
     "Jellyfin.Server (nowebclient)": {
       "commandName": "Project",
-      "commandLineArgs": "--nowebclient"
+      "commandLineArgs": "--nowebclient",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
     }
   }
 }