public void WebServerStaticMethodWithConsole() { const string errorMessage = "THIS IS AN ERROR"; var instance = WebServer.CreateWithConsole(Resources.ServerAddress); Assert.AreEqual(instance.Log.GetType(), typeof(SimpleConsoleLog), "Log is SimpleConsoleLog"); // TODO: Grab console output instance.Log.Error(errorMessage); instance.Log.DebugFormat("Test {0}", errorMessage); instance.Log.ErrorFormat("Test {0}", errorMessage); instance.Log.Info(errorMessage); instance.Log.InfoFormat("Test {0}", errorMessage); instance.Log.WarnFormat("Test {0}", errorMessage); }
/// <summary> /// Load WebServer instance /// </summary> /// <param name="args"></param> private static void Main(string[] args) { var options = new Options(); Console.WriteLine("Unosquare.Labs.EmbedIO Web Server"); if (!Parser.Default.ParseArguments(args, options)) { return; } Console.WriteLine(" Command-Line Utility: Press any key to stop the server."); var serverUrl = "http://localhost:" + options.Port + "/"; using ( var server = options.NoVerbose ? WebServer.Create(serverUrl) : WebServer.CreateWithConsole(serverUrl)) { if (Properties.Settings.Default.UseLocalSessionModule) { server.WithLocalSession(); } server.EnableCors().WithStaticFolderAt(options.RootPath, defaultDocument: Properties.Settings.Default.HtmlDefaultDocument); server.Module <StaticFilesModule>().DefaultExtension = Properties.Settings.Default.HtmlDefaultExtension; server.Module <StaticFilesModule>().UseRamCache = Properties.Settings.Default.UseRamCache; if (options.ApiAssemblies != null && options.ApiAssemblies.Count > 0) { foreach (var api in options.ApiAssemblies) { server.Log.DebugFormat("Registering Assembly {0}", api); LoadApi(api, server); } } // start the server server.RunAsync(); Console.ReadKey(true); } }
/// <summary> /// Entry point /// </summary> /// <param name="args"></param> private static void Main(string[] args) { try { OwinServerFactory.Log = new SimpleConsoleLog(); Console.WriteLine("Do you want to run EmbedIO as OWIN Server? (y/n)"); var response = Console.ReadLine(); if (response != null && response.ToLower() == "y") { var options = new StartOptions { ServerFactory = OwinServerFactory.ServerFactoryName, Port = 4578 }; using (WebApp.Start <Startup>(options)) { OwinServerFactory.Log.DebugFormat("Running a http server on port {0}", options.Port); Console.ReadKey(); } } else { using (var webServer = WebServer .CreateWithConsole("http://localhost:4578") .WithWebApi(typeof(PeopleController).Assembly) .UseOwin((owinApp) => owinApp .UseDirectoryBrowser() .UseRazor(Startup.InitRoutes))) { webServer.RunAsync(); Console.ReadKey(); } } } catch (Exception ex) { OwinServerFactory.Log.Error(ex); Console.ReadKey(); } }
/// <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]; } // Create basic authentication provider var basicAuthProvider = new BasicAuthorizationServerProvider(); // Create Webserver with console logger and attach LocalSession and Static // files module var server = WebServer.CreateWithConsole(url).EnableCors(); server.RegisterModule(new BearerTokenModule(basicAuthProvider, new[] { "/secure.html" })); server.RegisterModule(new JsonServerModule(jsonPath: Path.Combine(WebRootPath, "database.json"))); server.RegisterModule(new MarkdownStaticModule(WebRootPath)); server.RunAsync(); // Fire up the browser to show the content if we are debugging! #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); server.Dispose(); }