public static async Task BuildPage(HttpResponse response, IApplication application, OpenInput input) { var styleTags = HomeEndpoint.styleTags().Select(x => x.ToString()).Join("\n "); await response.Body.WriteAsync($@" <html> <head> <title>Storyteller 4</title> {styleTags} ").ConfigureAwait(false); await writeInitialDataIntoPage(response, application).ConfigureAwait(false); await response.Body.WriteAsync($@" </head> <body> <div id=""header-container""></div> <div id=""body-pane"" class=""container""></div> <div id=""main""></div> ").ConfigureAwait(false); await response.Body.WriteAsync(ScriptTag(input.HotReloadFlag).ToString()).ConfigureAwait(false); await response.Body.WriteAsync(@" </body> </html> ").ConfigureAwait(false); }
private void startWebServer(string hostname, int port, WebSocketsHandler webSockets) { #if NET46 var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; #else var baseDirectory = AppContext.BaseDirectory; #endif var hostBuilder = new WebHostBuilder() .UseKestrel() .UseContentRoot(baseDirectory) .Configure(app => { app.UseWebSockets(); app.Use(async(http, next) => { if (http.WebSockets.IsWebSocketRequest) { await webSockets.HandleSocket(http).ConfigureAwait(false); } else { await next().ConfigureAwait(false); } }); #if DEBUG configureStaticFiles(app); #endif app.Run(async http => { if (http.Request.Path == "/favicon.ico") { await writeFavicon(http).ConfigureAwait(false); return; } try { http.Response.ContentType = "text/html"; await HomeEndpoint.BuildPage(http.Response, _application, _input).ConfigureAwait(false); } catch (Exception e) { Console.WriteLine(e.ToString()); throw; } }); }); _server = hostBuilder.Start($"http://{hostname}:{port}"); }