Created
February 13, 2017 16:02
-
-
Save mvrmoreira/cadc8e4165b905127caad517cecd9958 to your computer and use it in GitHub Desktop.
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 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