fix redirect

This commit is contained in:
tparnell
2020-09-10 11:59:10 -04:00
parent fc74be52e4
commit 68f156df95
2 changed files with 71 additions and 78 deletions

View File

@@ -1,20 +1,16 @@
using System; using System;
using System.IO; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
namespace TerribleDev namespace aka.terribledev.io
{ {
public static class redirectFunction
public static class http
{ {
public static Dictionary<string, string> RoutesDictionary = new Dictionary<string, string>() public static Dictionary<string, string> RoutesDictionary = new Dictionary<string, string>()
{ {
@@ -37,21 +33,18 @@ namespace TerribleDev
["web/jsmobileconf19"] = "https://1drv.ms/p/s!ApmZsxwTwlbwgYgp4R33QLD5fpeVxA", ["web/jsmobileconf19"] = "https://1drv.ms/p/s!ApmZsxwTwlbwgYgp4R33QLD5fpeVxA",
["fun"] = "https://www.youtube.com/watch?v=dQw4w9WgXcQ", ["fun"] = "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
}; };
[FunctionName("http")]
public static class redirectFunctionTrig public static IActionResult Run(
{ [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "{*path}")] HttpRequest req,
[FunctionName("redirectFunctionTrig")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "{*path}")]
HttpRequest req,
ILogger log, ILogger log,
string path) string path)
{ {
log.LogInformation($"redirect triggered: {DateTime.Now}"); log.LogInformation($"redirect triggered: {DateTime.Now}");
var name = path?.ToString().TrimEnd('/') ?? string.Empty; var name = path?.ToString().Trim('/') ?? string.Empty;
if (string.Equals(name, "livecheck")) if (string.Equals(name, "livecheck"))
{ {
req.HttpContext.Response.GetTypedHeaders().CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue() { req.HttpContext.Response.GetTypedHeaders().CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue()
{
Private = true, Private = true,
NoCache = true, NoCache = true,
NoStore = true, NoStore = true,
@@ -59,7 +52,8 @@ namespace TerribleDev
}; };
return new OkObjectResult("Hi! ^_^"); return new OkObjectResult("Hi! ^_^");
} }
req.HttpContext.Response.GetTypedHeaders().CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue() { req.HttpContext.Response.GetTypedHeaders().CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue()
{
Public = true, Public = true,
MaxAge = TimeSpan.FromDays(1) MaxAge = TimeSpan.FromDays(1)
}; };
@@ -74,4 +68,3 @@ namespace TerribleDev
} }
} }
} }
}

View File

@@ -4,7 +4,7 @@
<AzureFunctionsVersion>v3</AzureFunctionsVersion> <AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" /> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="host.json"> <None Update="host.json">