Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active November 7, 2019 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsscoder/5019135 to your computer and use it in GitHub Desktop.
Save gsscoder/5019135 to your computer and use it in GitHub Desktop.
namespace OwinHttpListenerWithNancyFx
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Nancy;
using Owin.Listener;
public class HelloWorldModule : NancyModule
{
public HelloWorldModule()
{
Get["/"] = _ => "<a href=\"/hello\">go here</a>";
Get["/hello"] = _ => "Hello, Nancy OWIN!";
}
}
class Program
{
static void Main(string[] args)
{
var nancyOwin = new Nancy.Owin.NancyOwinHost(EmptyApp, new DefaultNancyBootstrapper());
var listener = new OwinHttpListener(nancyOwin.Invoke, new IPAddress(new byte[] { 0, 0, 0, 0 }), 8899);
listener.Start();
listener.ListenAsync().Wait();
Console.ReadLine();
listener.Stop();
}
static Task EmptyApp(IDictionary<string, object> env)
{
var tcs = new TaskCompletionSource<object>();
tcs.SetResult(null);
return tcs.Task;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment