/// <summary> /// Render first html GET request. /// </summary> private static async Task <string> WebsiteServerSideRenderingAsync(HttpContext context, AppSelector appSelector, AppJson appJson) { string url; if (UtilServer.IsIssServer) { // Running on IIS Server. url = context.Request.IsHttps ? "https://" : "http://"; url += context.Request.Host.ToUriComponent() + "/Framework/Framework.Angular/server/main.js"; // Url of server side rendering when running on IIS Server } else { // Running in Visual Studio. url = "http://localhost:4000/"; // Url of server side rendering when running in Visual Studio } // Process AppJson string jsonClient = await appSelector.ProcessAsync(context, appJson); // Process (For first server side rendering) // Server side rendering POST. string folderNameServer = appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/Framework/"); string serverSideRenderView = UtilFramework.FolderNameParse(folderNameServer, "/index.html"); serverSideRenderView = HttpUtility.UrlEncode(serverSideRenderView); url += "?view=" + serverSideRenderView; bool isServerSideRendering = ConfigServer.Load().IsServerSideRendering; string indexHtml; if (isServerSideRendering) { // index.html server side rendering indexHtml = await UtilServer.WebPost(url, jsonClient); // Server side rendering POST. http://localhost:50919/Framework/Framework.Angular/server.js?view=Application.Website%2fDefault%2findex.html } else { // index.html serve directly string fileName = UtilServer.FolderNameContentRoot() + UtilFramework.FolderNameParse(appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/"), "/index.html"); indexHtml = UtilFramework.FileLoad(fileName); } // Set jsonBrowser in index.html. string scriptFind = "</app-root>"; //" <script>var jsonBrowser={}</script>"; // For example Html5Boilerplate build process renames var jsonBrowser to a. string scriptReplace = "</app-root><script>var jsonBrowser = " + jsonClient + "</script>"; if (isServerSideRendering) { indexHtml = UtilFramework.Replace(indexHtml, scriptFind, scriptReplace); } // Add Angular scripts scriptFind = "</body></html>"; scriptReplace = "<script src=\"runtime.js\" defer></script><script src=\"polyfills.js\" defer></script><script src=\"main.js\" defer></script>" + "</body></html>"; indexHtml = UtilFramework.Replace(indexHtml, scriptFind, scriptReplace); return(indexHtml); }