Created
February 10, 2015 16:18
-
-
Save vbfox/e3fd38ab1145dfa69973 to your computer and use it in GitHub Desktop.
Nancy Self-Host to redirect completely to another domain including 307 for POST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Nancy; | |
using Nancy.Hosting.Self; | |
using Nancy.Responses; | |
namespace NancyRedirect | |
{ | |
public class Program : NancyModule | |
{ | |
static void Main() | |
{ | |
var config = new HostConfiguration(); | |
config.UrlReservations.CreateAutomatically = true; | |
using (var host = new NancyHost(new Uri("http://localhost:1234"), new DefaultNancyBootstrapper(), config)) | |
{ | |
host.Start(); | |
Console.ReadLine(); | |
} | |
} | |
public Program() | |
{ | |
Get["/{rest*}"] = Redirect; | |
Post["/{rest*}"] = Redirect; | |
} | |
private dynamic Redirect(dynamic _) | |
{ | |
var canSeeOther = Request.Method == "GET" || Request.Method == "HEAD"; | |
return new RedirectResponse("https://google.com" + Request.Url.Path, | |
canSeeOther ? RedirectResponse.RedirectType.SeeOther : RedirectResponse.RedirectType.Temporary); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment