Skip to content

Instantly share code, notes, and snippets.

@vbfox
Created February 10, 2015 16:18
Show Gist options
  • Save vbfox/e3fd38ab1145dfa69973 to your computer and use it in GitHub Desktop.
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
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