Better reverse proxy support

Added "base path override" config option that makes all links and
redirects work with your reverse proxy.
Fixed post config update reload to work properly.
Make redirects and ajax calls use relative pathing.
This commit is contained in:
Michael Robinson
2016-01-08 15:45:08 -07:00
parent 71c583d359
commit 42ec634cd3
10 changed files with 100 additions and 62 deletions

View File

@@ -19,6 +19,7 @@ using System.Net;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
@@ -32,7 +33,8 @@ namespace Jackett.Services
void ReserveUrls(bool doInstall = true);
ServerConfig Config { get; }
void SaveConfig();
Uri ConvertToProxyLink(Uri link, string serverUrl, string indexerId, string action = "dl", string file = "t.torrent");
Uri ConvertToProxyLink(Uri link, string serverUrl, string indexerId, string action = "dl", string file = "t.torrent");
string BasePath();
}
public class ServerService : IServerService
@@ -77,6 +79,23 @@ namespace Jackett.Services
return new Uri(proxyLink);
}
public string BasePath()
{
if (config.BasePathOverride == null || config.BasePathOverride == "") {
return "/";
}
var path = config.BasePathOverride;
if (!path.EndsWith("/"))
{
path = path + "/";
}
if (!path.StartsWith("/"))
{
path = "/" + path;
}
return path;
}
private void LoadConfig()
{
// Load config
@@ -139,6 +158,7 @@ namespace Jackett.Services
logger.Info("Starting web server at " + config.GetListenAddresses()[0]);
var startOptions = new StartOptions();
config.GetListenAddresses().ToList().ForEach(u => startOptions.Urls.Add(u));
Startup.BasePath = BasePath();
_server = WebApp.Start<Startup>(startOptions);
logger.Debug("Web server started");
updater.StartUpdateChecker();