summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Startup.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Startup.cs')
-rw-r--r--src/SMAPI.Web/Startup.cs18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs
index e19593c7..0f656e55 100644
--- a/src/SMAPI.Web/Startup.cs
+++ b/src/SMAPI.Web/Startup.cs
@@ -1,4 +1,3 @@
-using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Rewrite;
@@ -9,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using StardewModdingAPI.Web.Framework;
using StardewModdingAPI.Web.Framework.ConfigModels;
+using StardewModdingAPI.Web.Framework.RewriteRules;
namespace StardewModdingAPI.Web
{
@@ -65,13 +65,15 @@ namespace StardewModdingAPI.Web
loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app
- .UseRewriter(
- new RewriteOptions()
- .Add(new RewriteSubdomainRule
- {
- ExceptPaths = new[] { new Regex("^/Content", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase) }
- })
- ) // convert subdomain.smapi.io => smapi.io/subdomain for routing
+ .UseRewriter(new RewriteOptions()
+ // convert subdomain.smapi.io => smapi.io/subdomain for routing
+ .Add(new ConditionalRewriteSubdomainRule(
+ shouldRewrite: req =>
+ req.Host.Host != "localhost"
+ && (req.Host.Host.StartsWith("api.") || req.Host.Host.StartsWith("log."))
+ && !req.Path.StartsWithSegments("/content")
+ ))
+ )
.UseStaticFiles() // wwwroot folder
.UseMvc();
}