/// <summary> /// Returns true, if file found in folder "Application.Server/Framework/Framework.Angular/browser". /// </summary> private async Task <bool> AngularBrowserFileAsync(HttpContext context, string path) { // Fallback Application.Server/Framework/Framework.Angular/browser if (UtilServer.PathIsFileName(path)) { // Serve fileName string fileName = UtilServer.FolderNameContentRoot() + "Framework/Framework.Angular/browser" + path; if (fileName.EndsWith(angularBrowserFileNameJsSuffix)) { // Prevent for example two main.js. Angular js can not be overridden by Website // Application.Website/LayoutDefault/dist/main.js // Application.Server/Framework/Framework.Angular/browser/main.js fileName = fileName.Substring(0, fileName.Length - angularBrowserFileNameJsSuffix.Length) + ".js"; } if (File.Exists(fileName)) { context.Response.ContentType = UtilServer.ContentType(fileName); await context.Response.SendFileAsync(fileName); return(true); } } return(false); }
/// <summary> /// Browser GET request to download file. /// </summary> private static async Task <bool> FileDownloadAsync(HttpContext context, string path, byte[] data) { bool result = false; if (data != null) { UtilFramework.Assert(data != null); string fileName = UtilFramework.FolderNameParse(null, path); context.Response.ContentType = UtilServer.ContentType(fileName); await context.Response.Body.WriteAsync(data, 0, data.Length); result = true; } return(result); }
/// <summary> /// Handle client web POST /app.json /// </summary> private static async Task <bool> Post(HttpContext context, string path, AppSelector appSelector) { bool result = false; if (path == "/app.json") { string jsonClient = await appSelector.ProcessAsync(context, null); // Process (Client http post) context.Response.ContentType = UtilServer.ContentType(path); await context.Response.WriteAsync(jsonClient); result = true; } return(result); }
/// <summary> /// Returns true, if file found in folder "Application.Server/Framework/Application.Website/" /// </summary> private async Task <bool> WebsiteFileAsync(HttpContext context, string path, AppSelector appSelector) { bool result = false; if (UtilServer.NavigatePathIsFileName(path)) { // Serve fileName string fileName = UtilServer.FolderNameContentRoot() + UtilFramework.FolderNameParse(appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/"), path); if (File.Exists(fileName)) { context.Response.ContentType = UtilServer.ContentType(fileName); await context.Response.SendFileAsync(fileName); return(true); } } return(result); }
/// <summary> /// Returns true, if file found in folder "Application.Server/Framework/Framework.Angular/browser". /// </summary> private async Task <bool> AngularBrowserFileAsync(HttpContext context, string path) { // Fallback Application.Server/Framework/Framework.Angular/browser if (UtilServer.NavigatePathIsFileName(path)) { // Serve fileName string fileName = UtilServer.FolderNameContentRoot() + "Framework/Framework.Angular/browser" + path; if (File.Exists(fileName)) { context.Response.ContentType = UtilServer.ContentType(fileName); await context.Response.SendFileAsync(fileName); return(true); } } return(false); }
/// <summary> /// Divert request to "Application.Server/Framework/Application.Website/" /// </summary> private static async Task <bool> WebsiteServerSideRenderingAsync(HttpContext context, string navigatePath, AppSelector appSelector, AppJson appJson) { bool result = false; // FolderNameServer string folderNameServer = appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/"); // FolderName string folderName = UtilServer.FolderNameContentRoot() + folderNameServer; if (!Directory.Exists(folderName)) { throw new Exception(string.Format("Folder does not exis! Make sure cli build command did run. ({0})", folderName)); } // Index.html string pathIndexHtml = navigatePath; if (!UtilServer.NavigatePathIsFileName(navigatePath)) { pathIndexHtml += "index.html"; } // FileName string fileName = UtilFramework.FolderNameParse(folderName, pathIndexHtml); if (File.Exists(fileName)) { if (fileName.EndsWith(".html") && UtilFramework.StringNull(appSelector.AppTypeName) != null) { context.Response.ContentType = UtilServer.ContentType(fileName); string htmlIndex = await WebsiteServerSideRenderingAsync(context, appSelector, appJson); await context.Response.WriteAsync(htmlIndex); result = true; } } return(result); }