summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web.LegacyRedirects/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-01 21:55:20 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-02 20:14:07 -0500
commit5f532c259d5d3050bd6a053659067617db136d57 (patch)
tree06b8bf7ac63ccab8be27908002612a53d5975075 /src/SMAPI.Web.LegacyRedirects/Framework
parent8766a79408ce79bd632c1fe1c9b17ab0a7a6a976 (diff)
downloadSMAPI-5f532c259d5d3050bd6a053659067617db136d57.tar.gz
SMAPI-5f532c259d5d3050bd6a053659067617db136d57.tar.bz2
SMAPI-5f532c259d5d3050bd6a053659067617db136d57.zip
migrate from AWS to Azure
This commit migrates from subdomains to paths (due to the cost of a wildcard HTTPS certificate on Azure), adds a web project to redirect the old subdomains from AWS to Azure, and removes AWS-specific hacks.
Diffstat (limited to 'src/SMAPI.Web.LegacyRedirects/Framework')
-rw-r--r--src/SMAPI.Web.LegacyRedirects/Framework/LambdaRewriteRule.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/SMAPI.Web.LegacyRedirects/Framework/LambdaRewriteRule.cs b/src/SMAPI.Web.LegacyRedirects/Framework/LambdaRewriteRule.cs
new file mode 100644
index 00000000..e5138e5c
--- /dev/null
+++ b/src/SMAPI.Web.LegacyRedirects/Framework/LambdaRewriteRule.cs
@@ -0,0 +1,37 @@
+using System;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Rewrite;
+
+namespace SMAPI.Web.LegacyRedirects.Framework
+{
+ /// <summary>Rewrite requests to prepend the subdomain portion (if any) to the path.</summary>
+ /// <remarks>Derived from <a href="https://stackoverflow.com/a/44526747/262123" />.</remarks>
+ internal class LambdaRewriteRule : IRule
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Rewrite an HTTP request if needed.</summary>
+ private readonly Action<RewriteContext, HttpRequest, HttpResponse> Rewrite;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="rewrite">Rewrite an HTTP request if needed.</param>
+ public LambdaRewriteRule(Action<RewriteContext, HttpRequest, HttpResponse> rewrite)
+ {
+ this.Rewrite = rewrite ?? throw new ArgumentNullException(nameof(rewrite));
+ }
+
+ /// <summary>Applies the rule. Implementations of ApplyRule should set the value for <see cref="RewriteContext.Result" /> (defaults to RuleResult.ContinueRules).</summary>
+ /// <param name="context">The rewrite context.</param>
+ public void ApplyRule(RewriteContext context)
+ {
+ HttpRequest request = context.HttpContext.Request;
+ HttpResponse response = context.HttpContext.Response;
+ this.Rewrite(context, request, response);
+ }
+ }
+}