Skip to content

Commit

Permalink
always redirect to bmm.bcc.media unless it has ?force-old
Browse files Browse the repository at this point in the history
  • Loading branch information
kkuepper committed Jun 18, 2024
1 parent 8004757 commit cdcb702
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
21 changes: 21 additions & 0 deletions BMM.Website/HtmlResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net.Mime;
using System.Text;
using Microsoft.AspNetCore.Mvc;

namespace BMM.Website;

Expand Down Expand Up @@ -54,4 +55,24 @@ public async Task ExecuteAsync(HttpContext httpContext)
httpContext.Response.ContentLength = Encoding.UTF8.GetByteCount(adjustedHtml);
await httpContext.Response.WriteAsync(adjustedHtml);
}
}

public class RedirectResult : IResult
{
public async Task ExecuteAsync(HttpContext httpContext)
{
var newUrl = $"https://bmm.bcc.media{httpContext.Request.Path}{httpContext.Request.QueryString}";

httpContext.Response.StatusCode = StatusCodes.Status302Found;
httpContext.Response.Headers.Add("Location", newUrl);
await Task.CompletedTask;
}
}

public static class Helper
{
public static IResult Result()
{
return new RedirectResult();
}
}
11 changes: 10 additions & 1 deletion BMM.Website/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Globalization;
using BMM.Website;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Rewrite;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -11,7 +12,15 @@

var indexFile = File.ReadAllText("wwwroot/index.html");

var handler = () => new HtmlResult(indexFile);
var handler = (HttpContext context) =>
{
if (context.Request.QueryString.ToUriComponent().Contains("force-old"))
{
return new HtmlResult(indexFile);
}
return Helper.Result();
};

app.MapGet("/", handler);
app.MapGet("index.html", handler);
Expand Down

0 comments on commit cdcb702

Please sign in to comment.