Skip to content

Instantly share code, notes, and snippets.

@mvrmoreira
Created February 13, 2017 16:02
Show Gist options
  • Save mvrmoreira/cadc8e4165b905127caad517cecd9958 to your computer and use it in GitHub Desktop.
Save mvrmoreira/cadc8e4165b905127caad517cecd9958 to your computer and use it in GitHub Desktop.
using Mono.Unix;
using Mono.Unix.Native;
using Nancy.Hosting.Self;
using System;
namespace Nala
{
class Program
{
static void Main(string[] args)
{
var uri = "http://localhost:8888";
Console.WriteLine("Starting Nancy on " + uri);
// initialize an instance of NancyHost
var host = new NancyHost(new Uri(uri));
host.Start(); // start hosting
// check if we're running on mono
if (Type.GetType("Mono.Runtime") != null)
{
// on mono, processes will usually run as daemons - this allows you to listen
// for termination signals (ctrl+c, shutdown, etc) and finalize correctly
UnixSignal.WaitAny(new[] {
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGTERM),
new UnixSignal(Signum.SIGQUIT),
new UnixSignal(Signum.SIGHUP)
});
}
else
{
Console.ReadLine();
}
Console.WriteLine("Stopping Nancy");
host.Stop(); // stop hosting
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment