mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Reverse proxy support for Kestrel
This commit is contained in:
@@ -72,6 +72,8 @@ namespace Jackett.Server.Controllers
|
||||
[HttpPost]
|
||||
public IActionResult UpdateConfig([FromBody]Common.Models.DTO.ServerConfig config)
|
||||
{
|
||||
bool webHostRestartNeeded = false;
|
||||
|
||||
var originalPort = serverConfig.Port;
|
||||
var originalAllowExternal = serverConfig.AllowExternal;
|
||||
int port = config.port;
|
||||
@@ -91,6 +93,11 @@ namespace Jackett.Server.Controllers
|
||||
string omdbApiKey = config.omdbkey;
|
||||
string omdbApiUrl = config.omdburl;
|
||||
|
||||
if (config.basepathoverride != serverConfig.BasePathOverride)
|
||||
{
|
||||
webHostRestartNeeded = true;
|
||||
}
|
||||
|
||||
serverConfig.UpdateDisabled = updateDisabled;
|
||||
serverConfig.UpdatePrerelease = preRelease;
|
||||
serverConfig.BasePathOverride = basePathOverride;
|
||||
@@ -164,8 +171,7 @@ namespace Jackett.Server.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(500);
|
||||
Helper.RestartWebHost();
|
||||
webHostRestartNeeded = true;
|
||||
}
|
||||
|
||||
if (saveDir != serverConfig.BlackholeDir)
|
||||
@@ -182,6 +188,13 @@ namespace Jackett.Server.Controllers
|
||||
configService.SaveConfig(serverConfig);
|
||||
}
|
||||
|
||||
if (webHostRestartNeeded)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
logger.Info("Restarting webhost due to configuration change");
|
||||
Helper.RestartWebHost();
|
||||
}
|
||||
|
||||
serverConfig.ConfigChanged();
|
||||
|
||||
return Json(serverConfig);
|
||||
|
@@ -1,25 +0,0 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Rewrite;
|
||||
using System;
|
||||
|
||||
namespace Jackett.Server.Middleware
|
||||
{
|
||||
public class RewriteRules
|
||||
{
|
||||
public static void RewriteBasePath(RewriteContext context)
|
||||
{
|
||||
var request = context.HttpContext.Request;
|
||||
|
||||
string serverBasePath = Helper.ServerService.BasePath() ?? string.Empty;
|
||||
|
||||
if (request.Path != null && request.Path.HasValue && serverBasePath.Length > 0
|
||||
&& (request.Path.Value.StartsWith(serverBasePath + "/", StringComparison.Ordinal)
|
||||
|| request.Path.Value.Equals(serverBasePath, StringComparison.Ordinal)))
|
||||
{
|
||||
string path = request.Path.Value.Substring(serverBasePath.Length);
|
||||
path = string.IsNullOrEmpty(path) ? "/" : path;
|
||||
request.Path = new PathString(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||
using Microsoft.AspNetCore.Rewrite;
|
||||
@@ -107,8 +108,19 @@ namespace Jackett.Server
|
||||
|
||||
app.UseCustomExceptionHandler();
|
||||
|
||||
string serverBasePath = Helper.ServerService.BasePath() ?? string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(serverBasePath))
|
||||
{
|
||||
app.UsePathBase(serverBasePath);
|
||||
}
|
||||
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
|
||||
var rewriteOptions = new RewriteOptions()
|
||||
.Add(RewriteRules.RewriteBasePath)
|
||||
.AddRewrite(@"^torznab\/([\w-]*)", "api/v2.0/indexers/$1/results/torznab", skipRemainingRules: true) //legacy torznab route
|
||||
.AddRewrite(@"^potato\/([\w-]*)", "api/v2.0/indexers/$1/results/potato", skipRemainingRules: true) //legacy potato route
|
||||
.Add(RedirectRules.RedirectToDashboard);
|
||||
|
Reference in New Issue
Block a user