/// <summary> /// Creates the web server. /// </summary> /// <param name="urls">The urls.</param> /// <returns></returns> private IWebServer CreateWebServer(string[] urls) { //remove built in console logger and register the override that wraps serilog #if DEBUG Logger.UnregisterLogger <ConsoleLogger>(); #endif Logger.RegisterLogger(new WebServerLogger(Log.Logger)); WebServerOptions options = new WebServerOptions(); options.WithUrlPrefixes(urls); options.WithMode(HttpListenerMode.EmbedIO); var server = new EmbedIO.WebServer(options); server.WithWebApi("/api", m => m .WithController(() => _controller)); return(server); }
public WebServer(IUnityContainer container, string pathStaticFiles = null, bool developmentMode = false) { var config = container.Resolve <Config>(); scheduler = container.Resolve <IScheduler>(); shutdown = container.IsRegistered <IShutdown>() ? container.Resolve <IShutdown>() : null; var options = new WebServerOptions() .WithMode(HttpListenerMode.Microsoft) .WithUrlPrefix(config.HostingURI); var frontendSettings = new { appName = getApplicationName(), apiUrl = $"{config.HostingURI}/api", isService = shutdown == null }; server = new EmbedServer(options); // Из-за отсутствия обработчика ошибок в EmbedIO приходится использовать такой странный способ проверки занятости префикса // Конкретнее: https://github.com/unosquare/embedio/blob/3.1.3/src/EmbedIO/WebServerBase%601.cs#L208 // Проверяется только токен отмены, а все ошибки включая запуск HttpListener будут проигнорированы без всякого сообщения server.Listener.Start(); server.Listener.Stop(); if (developmentMode) { server.WithCors(); } server.WithModule(nameof(WebSocketStatus), new WebSocketStatus(scheduler, "/ws-status")); server.WithWebApi("/api", m => m.WithController(() => new JobController(shutdown, scheduler))) .WithModule(new ActionModule("/settings.json", HttpVerbs.Get, ctx => ctx.SendDataAsync(frontendSettings))); if (pathStaticFiles != null) { server.WithStaticFolder("/", pathStaticFiles, true); } server.StateChanged += (s, e) => logger.Debug($"New State: {e.NewState}"); server.RunAsync(); }
public EmbedIO.WebServer ConfigWebController(string id, string path, EmbedIO.WebServer webServer) { return(webServer.WithWebApi(id, path, EmbedIOResponseSerializerCallback, module => module.WithController(() => new AlbumWebController(GetFromCache)))); }