aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Monteiro <marknr.monteiro@protonmail.com>2020-02-28 20:49:04 +0100
committerMark Monteiro <marknr.monteiro@protonmail.com>2020-03-11 22:54:54 +0100
commit29bad073ebeb10813c6468b6159ce3bd06398134 (patch)
treea17f43ec7703d8daf79ebd3561460399b1b68129
parent3f4b9e9a81278c6f5c817036a7ae52b6f70557e4 (diff)
Use config setting to decide if web content should be hosted
Also fail server startup if web content is expected but missing
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs5
-rw-r--r--Emby.Server.Implementations/EntryPoints/StartupWizard.cs4
-rw-r--r--Jellyfin.Server/Program.cs25
-rw-r--r--MediaBrowser.Controller/IServerApplicationHost.cs5
4 files changed, 18 insertions, 21 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 789b8724c..8ea188724 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -240,13 +240,10 @@ namespace Emby.Server.Implementations
public int HttpsPort { get; private set; }
/// <summary>
- /// Gets the content root for the webhost. If the webhost is not serving static web content, this will be null.
+ /// Gets the content root for the webhost.
/// </summary>
public string ContentRoot { get; private set; }
- /// <inheritdoc/>
- public bool IsHostingContent => ContentRoot != null;
-
/// <summary>
/// Gets the server configuration manager.
/// </summary>
diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs
index 6b7e2805b..7c2b3cd5f 100644
--- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs
+++ b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs
@@ -2,7 +2,9 @@ using System.Threading.Tasks;
using Emby.Server.Implementations.Browser;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Extensions;
using MediaBrowser.Controller.Plugins;
+using Microsoft.Extensions.Configuration;
namespace Emby.Server.Implementations.EntryPoints
{
@@ -36,7 +38,7 @@ namespace Emby.Server.Implementations.EntryPoints
return Task.CompletedTask;
}
- if (!_appHost.IsHostingContent)
+ if (_appHost.Resolve<IConfiguration>().IsNoWebContent())
{
BrowserLauncher.OpenSwaggerPage(_appHost);
}
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index 7e03b0c9c..843eb9ea9 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -19,7 +19,7 @@ using Emby.Server.Implementations.Networking;
using Jellyfin.Drawing.Skia;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing;
-using MediaBrowser.Model.Globalization;
+using MediaBrowser.Controller.Extensions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -177,7 +177,7 @@ namespace Jellyfin.Server
ServiceCollection serviceCollection = new ServiceCollection();
await appHost.InitAsync(serviceCollection).ConfigureAwait(false);
- var host = CreateWebHostBuilder(appHost, serviceCollection).Build();
+ var host = CreateWebHostBuilder(appHost, serviceCollection, appConfig).Build();
// A bit hacky to re-use service provider since ASP.NET doesn't allow a custom service collection.
appHost.ServiceProvider = host.Services;
@@ -221,7 +221,7 @@ namespace Jellyfin.Server
}
}
- private static IWebHostBuilder CreateWebHostBuilder(ApplicationHost appHost, IServiceCollection serviceCollection)
+ private static IWebHostBuilder CreateWebHostBuilder(ApplicationHost appHost, IServiceCollection serviceCollection, IConfiguration appConfig)
{
var webhostBuilder = new WebHostBuilder()
.UseKestrel(options =>
@@ -268,9 +268,18 @@ namespace Jellyfin.Server
})
.UseStartup<Startup>();
- // Set the root directory for static content, if one exists
- if (appHost.IsHostingContent)
+ if (!appConfig.IsNoWebContent())
{
+ // Fail startup if the web content does not exist
+ if (!Directory.Exists(appHost.ContentRoot) || !Directory.GetFiles(appHost.ContentRoot).Any())
+ {
+ throw new InvalidOperationException(
+ "The server is expected to host web content, but the provided content directory is either " +
+ $"invalid or empty: {appHost.ContentRoot}. If you do not want to host web content with the " +
+ $"server, you may set the '{MediaBrowser.Controller.Extensions.ConfigurationExtensions.NoWebContentKey}' flag.");
+ }
+
+ // Configure the web host to host the static web content
webhostBuilder.UseContentRoot(appHost.ContentRoot);
}
@@ -404,12 +413,6 @@ namespace Jellyfin.Server
}
}
- // Reset webDir if the directory does not exist, or is empty
- if (!Directory.Exists(webDir) || !Directory.GetFiles(webDir).Any())
- {
- webDir = null;
- }
-
// logDir
// IF --logdir
// ELSE IF $JELLYFIN_LOG_DIR
diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs
index 134ed110b..25f0905eb 100644
--- a/MediaBrowser.Controller/IServerApplicationHost.cs
+++ b/MediaBrowser.Controller/IServerApplicationHost.cs
@@ -17,11 +17,6 @@ namespace MediaBrowser.Controller
event EventHandler HasUpdateAvailableChanged;
/// <summary>
- /// Gets a value indicating whether the server is hosting the static web content from jellyfin-web.
- /// </summary>
- bool IsHostingContent { get; }
-
- /// <summary>
/// Gets the system info.
/// </summary>
/// <returns>SystemInfo.</returns>