/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> private static void Main(string[] args) { Console.WriteLine("Running at MONO: {0}", IsMono); var url = "http://*****:*****@unosquare.com" }); dbContext.People.Insert(new Person() { Name = "Geovanni Perez", Age = 32, EmailAddress = "*****@*****.**" }); dbContext.People.Insert(new Person() { Name = "Luis Gonzalez", Age = 29, EmailAddress = "*****@*****.**" }); #endif // Our web server is disposable. Note that if you don't want to use logging, // there are alternate constructors that allow you to skip specifying an ILog object. using (var server = new WebServer(url, new SimpleConsoleLog())) { // First, we will configure our web server by adding Modules. // Please note that order DOES matter. // ================================================================================================ // If we want to enable sessions, we simply register the LocalSessionModule // Beware that this is an in-memory session storage mechanism so, avoid storing very large objects. // You can use the server.GetSession() method to get the SessionInfo object and manupulate it. server.RegisterModule(new Modules.LocalSessionModule()); // Set the CORS Rules server.RegisterModule(new Modules.CorsModule( // Origins, separated by comma without last slash "http://client.cors-api.appspot.com,http://unosquare.github.io,http://run.plnkr.co", // Allowed headers "content-type, accept", // Allowed methods "post")); // Register the static files server. See the html folder of this project. Also notice that // the files under the html folder have Copy To Output Folder = Copy if Newer StaticFilesSample.Setup(server, !IsMono); // Register the Web Api Module. See the Setup method to find out how to do it // It registers the WebApiModule and registers the controller(s) -- that's all. server.WithWebApiController <PeopleController>(); // Register the WebSockets module. See the Setup method to find out how to do it // It registers the WebSocketsModule and registers the server for the given paths(s) WebSocketsSample.Setup(server); // Once we've registered our modules and configured them, we call the Run() method. // This is a non-blocking method (it return immediately) so in this case we avoid // disposing of the object until a key is pressed. //server.Run(); server.RunAsync(); // Fire up the browser to show the content! #if DEBUG #if !NETCOREAPP1_0 var browser = new System.Diagnostics.Process() { StartInfo = new System.Diagnostics.ProcessStartInfo(url) { UseShellExecute = true } }; browser.Start(); #endif #endif // Wait for any key to be pressed before disposing of our web server. // In a service we'd manage the lifecycle of of our web server using // something like a BackgroundWorker or a ManualResetEvent. Console.ReadKey(true); } }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> private static async Task Main(string[] args) { var url = "http://localhost:8787/"; if (args.Length > 0) { url = args[0]; } AppDbContext.InitDatabase(); var ctSource = new CancellationTokenSource(); ctSource.Token.Register(() => "Shutting down".Info()); // Set a task waiting for press key to exit #pragma warning disable 4014 Task.Run(() => #pragma warning restore 4014 { // Wait for any key to be pressed before disposing of our web server. Console.ReadLine(); ctSource.Cancel(); }, ctSource.Token); // Our web server is disposable. using (var server = new WebServer(new[] { url }, Constants.RoutingStrategy.Regex, HttpListenerMode.EmbedIO)) { // First, we will configure our web server by adding Modules. // Please note that order DOES matter. // ================================================================================================ // If we want to enable sessions, we simply register the LocalSessionModule // Beware that this is an in-memory session storage mechanism so, avoid storing very large objects. // You can use the server.GetSession() method to get the SessionInfo object and manipulate it. server.RegisterModule(new LocalSessionModule()); // Set the CORS Rules server.RegisterModule(new CorsModule( // Origins, separated by comma without last slash "http://unosquare.github.io,http://run.plnkr.co", // Allowed headers "content-type, accept", // Allowed methods "post")); // Register the static files server. See the html folder of this project. Also notice that // the files under the html folder have Copy To Output Folder = Copy if Newer StaticFilesSample.Setup(server, useGzip: Runtime.IsUsingMonoRuntime == false); // Register the Web Api Module. See the Setup method to find out how to do it // It registers the WebApiModule and registers the controller(s) -- that's all. server.WithWebApiController <PeopleController>(); // Register the WebSockets module. See the Setup method to find out how to do it // It registers the WebSocketsModule and registers the server for the given paths(s) WebSocketsSample.Setup(server); server.RegisterModule(new FallbackModule((ctx, ct) => ctx.JsonResponse(new { Message = "Error" }))); // Fire up the browser to show the content! var browser = new System.Diagnostics.Process { StartInfo = new System.Diagnostics.ProcessStartInfo(url.Replace("*", "localhost")) { UseShellExecute = true } }; browser.Start(); // Once we've registered our modules and configured them, we call the RunAsync() method. if (!ctSource.IsCancellationRequested) { await server.RunAsync(ctSource.Token); } "Bye".Info(); } }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> private static void Main(string[] args) { $"Running on Mono Runtime: {Runtime.IsUsingMonoRuntime}".Info(); var url = "http://*****:*****@unosquare.com" }); dbContext.People.Insert(new Person { Name = "Geovanni Perez", Age = 32, EmailAddress = "*****@*****.**" }); dbContext.People.Insert(new Person { Name = "Luis Gonzalez", Age = 29, EmailAddress = "*****@*****.**" }); #endif // Our web server is disposable. using (var server = new WebServer(url)) { // First, we will configure our web server by adding Modules. // Please note that order DOES matter. // ================================================================================================ // If we want to enable sessions, we simply register the LocalSessionModule // Beware that this is an in-memory session storage mechanism so, avoid storing very large objects. // You can use the server.GetSession() method to get the SessionInfo object and manupulate it. server.RegisterModule(new LocalSessionModule()); // Set the CORS Rules server.RegisterModule(new CorsModule( // Origins, separated by comma without last slash "http://unosquare.github.io,http://run.plnkr.co", // Allowed headers "content-type, accept", // Allowed methods "post")); // Register the static files server. See the html folder of this project. Also notice that // the files under the html folder have Copy To Output Folder = Copy if Newer StaticFilesSample.Setup(server, useGzip: Runtime.IsUsingMonoRuntime == false); // Register the Web Api Module. See the Setup method to find out how to do it // It registers the WebApiModule and registers the controller(s) -- that's all. server.WithWebApiController <PeopleController>(); // Register the WebSockets module. See the Setup method to find out how to do it // It registers the WebSocketsModule and registers the server for the given paths(s) WebSocketsSample.Setup(server); server.RegisterModule(new FallbackModule((ctx, ct) => ctx.JsonResponse(new { Message = "Error " }))); // Once we've registered our modules and configured them, we call the RunAsync() method. server.RunAsync(); // Fire up the browser to show the content! #if DEBUG var browser = new System.Diagnostics.Process { StartInfo = new System.Diagnostics.ProcessStartInfo(url.Replace("*", "localhost")) { UseShellExecute = true } }; browser.Start(); #endif // Wait for any key to be pressed before disposing of our web server. // In a service we'd manage the lifecycle of of our web server using // something like a BackgroundWorker or a ManualResetEvent. Console.ReadKey(true); } }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> private static void Main(string[] args) { var url = "http://localhost:9696/"; if (args.Length > 0) { url = args[0]; } // Our web server is disposable. Note that if you don't want to use logging, // there are alternate constructors that allow you to skip specifying an ILog object. using (var server = new WebServer(url, Log)) { // First, we will configure our web server by adding Modules. // Please note that order DOES matter. // ================================================================================================ // If we want to enable sessions, we simply register the LocalSessionModule // Beware that this is an in-memory session storage mechanism so, avoid storing very large objects. // You can use the server.GetSession() method to get the SessionInfo object and manupulate it. server.RegisterModule(new Modules.LocalSessionModule()); // Set the CORS Rules server.RegisterModule(new Modules.CorsModule( // Origins, separated by comma without last slash "http://client.cors-api.appspot.com,http://unosquare.github.io,http://run.plnkr.co", // Allowed headers "content-type, accept", // Allowed methods "post")); // Register the static files server. See the html folder of this project. Also notice that // the files under the html folder have Copy To Output Folder = Copy if Newer StaticFilesSample.Setup(server); // Register the Web Api Module. See the Setup method to find out how to do it // It registers the WebApiModule and registers the controller(s) -- that's all. RestApiSample.Setup(server); // Register the WebSockets module. See the Setup method to find out how to do it // It registers the WebSocketsModule and registers the server for the given paths(s) WebSocketsSample.Setup(server); // Once we've registered our modules and configured them, we call the Run() method. // This is a non-blocking method (it return immediately) so in this case we avoid // disposing of the object until a key is pressed. //server.Run(); server.RunAsync(); // Fire up the browser to show the content! #if DEBUG var browser = new System.Diagnostics.Process() { StartInfo = new System.Diagnostics.ProcessStartInfo(url) { UseShellExecute = true } }; browser.Start(); #endif // Wait for any key to be pressed before disposing of our web server. // In a service we'd manage the lifecycle of of our web server using // something like a BackgroundWorker or a ManualResetEvent. Console.ReadKey(true); } // Before exiting, we shutdown the logging subsystem. Logger.Shutdown(); }