public static void Main(string[] args) { string codeBase = Assembly.GetExecutingAssembly().CodeBase; string name = Path.GetFileName(codeBase); string secretToken = String.Empty; if (args.Length == 0) { Console.WriteLine ("Usage: " + name + " <secret token>"); Environment.Exit (0); } else { secretToken = args [0]; } StaticConfiguration.DisableErrorTraces = false; StaticConfiguration.EnableHeadRouting = true; var uri = "http://localhost:8888"; var urlReservations = new UrlReservations(); urlReservations.CreateAutomatically = true; var settings = new DefaultWebhookSettings (secretToken); var hostConfiguration = new HostConfiguration(); hostConfiguration.UrlReservations = urlReservations; // initialize an instance of NancyHost var host = new NancyHost (new Uri(uri), new CustomBootstrapper(settings), hostConfiguration); host.Start(); // start hosting Console.WriteLine("Started " + name + " on " + uri + " with secret token " + secretToken); Console.WriteLine (); Console.WriteLine ("Upon each wehook event, this program will post back a OK or No Match response after analyzing message hash."); Console.WriteLine ("Also make sure " + uri + "/exzeo_events is used as a callback url in your webhook registration" ); // 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 " + name + " application"); host.Stop (); // stop hosting }
static void Main(string[] args) { Console.WriteLine("Starting server!"); _trafficLightModel = TrafficlightModel.Instance; System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.Interval = 1000; aTimer.Enabled = true; NancyHost host; // Run the webserver with all privileges no need to ask the user for permission. var urlRes = new Nancy.Hosting.Self.UrlReservations { CreateAutomatically = true }; // Accept connections from outside localhost. var config = new HostConfiguration { RewriteLocalhost = true, UrlReservations = urlRes }; try { host = new NancyHost(config, new Uri("http://localhost:5000")); } catch (Exception e) { Console.WriteLine(e); throw; } // Attempt to start the server. try { host.Start(); } catch (Exception e) { Console.WriteLine(e); throw; } Console.ReadKey(); host.Stop(); }
public AchiIr500Server(INancyBootstrapper bootstrapper) { UrlReservations urlReservations = new UrlReservations {CreateAutomatically = true}; HostConfiguration serverConfig = new HostConfiguration {UrlReservations = urlReservations}; host = new NancyHost(bootstrapper, serverConfig, new Uri("http://localhost:9858")); }