/// <summary> /// Constructor. /// </summary> public AppSelector() { List <ConfigServerWebsite> result = new List <ConfigServerWebsite>(); string requestDomainName = UtilServer.RequestDomainName(); this.ConfigServer = ConfigServer.Load(); foreach (var website in ConfigServer.WebsiteList) { foreach (var item in website.DomainNameList) { if (item.DomainName == requestDomainName) { result.Add(website); } } } // Make sure Website has been found if (result.Count == 0) { throw new Exception(string.Format("Website not found! See also: ConfigServer.json (Domain={0}; Environment={1};)", requestDomainName, this.ConfigServer.EnvironmentName)); } if (result.Count > 1) { throw new Exception(string.Format("More than one website found! See also: ConfigServer.json ({0})", requestDomainName)); } this.Website = result.Single(); this.AppTypeName = Website.DomainNameList.Where(item => item.DomainName == requestDomainName).Single().AppTypeName; }
/// <summary> /// Copy from file ConfigCli.json to ConfigServer.json /// </summary> public static void ConfigToServer() { // Console.WriteLine("Copy runtime specific values from ConfigCli to ConfigServer"); // There is also other values not needed for runtime like DeployAzureGitUrl. var configCli = ConfigCli.Load(); var configServer = ConfigServer.Load(); // Environment configServer.EnvironmentName = configCli.EnvironmentGet().EnvironmentName; configServer.IsUseDeveloperExceptionPage = configCli.EnvironmentGet().IsUseDeveloperExceptionPage; // ConnectionString configServer.ConnectionStringFramework = configCli.EnvironmentGet().ConnectionStringFramework; configServer.ConnectionStringApplication = configCli.EnvironmentGet().ConnectionStringApplication; // Website configServer.WebsiteList.Clear(); foreach (var webSite in configCli.WebsiteList) { configServer.WebsiteList.Add(new ConfigServerWebsite() { DomainNameList = webSite.DomainNameList.Where(item => item.EnvironmentName == configCli.EnvironmentGet().EnvironmentName).Select(item => new ConfigServerWebsiteDomain { DomainName = item.DomainName, AppTypeName = item.AppTypeName }).ToList() }); } ConfigServer.Save(configServer); }
public static void Configure(IApplicationBuilder applicationBuilder) { UtilServer.ApplicationBuilder = applicationBuilder; var configServer = ConfigServer.Load(); if (UtilServer.IsIssServer == false) { // Running in Visual Studio environment. if (configServer.IsServerSideRendering) { UtilServer.StartUniversalServer(); } } if (configServer.IsUseDeveloperExceptionPage) { applicationBuilder.UseDeveloperExceptionPage(); } applicationBuilder.UseDefaultFiles(); // Used for index.html applicationBuilder.UseStaticFiles(); // Enable access to files in folder wwwwroot. applicationBuilder.UseSession(); if (configServer.IsUseHttpsRedirection) { // Enforce HTTPS in ASP.NET Core https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-5.0&tabs=visual-studio applicationBuilder.UseHsts(); applicationBuilder.UseHttpsRedirection(); } applicationBuilder.Run(new Request().RunAsync); }
/// <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); }
public static void Configure(IApplicationBuilder applicationBuilder) { UtilServer.ApplicationBuilder = applicationBuilder; if (UtilServer.IsIssServer == false) { if (ConfigServer.Load().IsServerSideRendering) { UtilServer.StartUniversalServer(); } } if (ConfigServer.Load().IsUseDeveloperExceptionPage) { applicationBuilder.UseDeveloperExceptionPage(); } applicationBuilder.UseDefaultFiles(); // Used for index.html applicationBuilder.UseStaticFiles(); // Enable access to files in folder wwwwroot. applicationBuilder.UseSession(); applicationBuilder.Run(new Request().RunAsync); }