From 4fef4f872e4f55ed8e9b966c9b6c2869a3ca0997 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Tue, 23 Jan 2018 20:40:37 +0100 Subject: [PATCH] basepath: add support for /jackett base path redirection --- src/Jackett/Services/ServerService.cs | 6 +++--- src/Jackett/Utils/RedirectMiddleware.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Jackett/Services/ServerService.cs b/src/Jackett/Services/ServerService.cs index 81c1528bd..8a222d60a 100644 --- a/src/Jackett/Services/ServerService.cs +++ b/src/Jackett/Services/ServerService.cs @@ -77,12 +77,12 @@ namespace Jackett.Services { if (config.BasePathOverride == null || config.BasePathOverride == "") { - return "/"; + return ""; } var path = config.BasePathOverride; - if (!path.EndsWith("/")) + if (path.EndsWith("/")) { - path = path + "/"; + path = path.TrimEnd('/'); } if (!path.StartsWith("/")) { diff --git a/src/Jackett/Utils/RedirectMiddleware.cs b/src/Jackett/Utils/RedirectMiddleware.cs index d076de866..e1abf8ed6 100644 --- a/src/Jackett/Utils/RedirectMiddleware.cs +++ b/src/Jackett/Utils/RedirectMiddleware.cs @@ -18,14 +18,14 @@ namespace Jackett.Utils { if (context.Request.Path != null && context.Request.Path.HasValue && context.Request.Path.Value.StartsWith(Engine.ServerConfig.RuntimeSettings.BasePath, StringComparison.Ordinal)) { - context.Request.Path = new PathString(context.Request.Path.Value.Substring(Engine.ServerConfig.RuntimeSettings.BasePath.Length - 1)); + context.Request.Path = new PathString(context.Request.Path.Value.Substring(Engine.ServerConfig.RuntimeSettings.BasePath.Length)); } if (context.Request.Path == null || string.IsNullOrWhiteSpace(context.Request.Path.ToString()) || context.Request.Path.ToString() == "/") { // 301 is the status code of permanent redirect context.Response.StatusCode = 302; - var redir = Engine.ServerConfig.RuntimeSettings.BasePath + "UI/Dashboard"; + var redir = Engine.ServerConfig.RuntimeSettings.BasePath + "/UI/Dashboard"; Engine.Logger.Info("redirecting to " + redir); context.Response.Headers.Set("Location", redir); }