From dd8adbdcaa9a1539e001962220cefe4f3dbb08ed Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 May 2024 13:34:55 -0700 Subject: [PATCH 1/3] small code cleanup --- src/Microsoft.TryDotNet/ContentGenerator.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TryDotNet/ContentGenerator.cs b/src/Microsoft.TryDotNet/ContentGenerator.cs index 0fdf34581..f25c52afd 100644 --- a/src/Microsoft.TryDotNet/ContentGenerator.cs +++ b/src/Microsoft.TryDotNet/ContentGenerator.cs @@ -22,16 +22,18 @@ public static Task GenerateEditorPageAsync(HttpRequest request) var hostUri = new Uri($"{scheme}://{request.Host.Value}", UriKind.Absolute); var wasmRunnerUri = new Uri(hostUri, "/wasmrunner"); - var commansdUri = new Uri(hostUri, "/commands"); + var commandsUri = new Uri(hostUri, "/commands"); + var enableLogging = false; if (request.Query.TryGetValue("enableLogging", out var enableLoggingString)) { enableLogging = enableLoggingString.FirstOrDefault()?.ToLowerInvariant() == "true"; } + var configuration = new { wasmRunnerUrl = wasmRunnerUri.AbsoluteUri, - commandsUrl = commansdUri.AbsoluteUri, + commandsUrl = commandsUri.AbsoluteUri, refererUrl = !string.IsNullOrWhiteSpace(referer) ? new Uri(referer, UriKind.Absolute) : null, enableLogging }; From c06ca9a940cf3536d9974878898d616e5da54074 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 May 2024 13:35:32 -0700 Subject: [PATCH 2/3] support /v2/editor route for backcompat --- src/Microsoft.TryDotNet/Program.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index 528a3dfd8..7ffc31c72 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -116,13 +116,16 @@ public static async Task CreateWebApplicationAsync(WebApplicatio app.MapFallbackToFile("/wasmrunner/{*path:nonfile}", "wasmrunner/index.html"); app.UseResponseCompression(); - app.MapGet("/editor", async (HttpRequest request, HttpResponse response) => + Func> editorHandler = async (request, response) => { var html = await ContentGenerator.GenerateEditorPageAsync(request); response.ContentType = MediaTypeNames.Text.Html; response.ContentLength = Encoding.UTF8.GetByteCount(html); return Results.Content(html); - }); + }; + + app.MapGet("/editor", editorHandler); + app.MapGet("/editor/v2", editorHandler); app.MapPost("/commands", async (HttpRequest request) => { @@ -131,12 +134,13 @@ public static async Task CreateWebApplicationAsync(WebApplicatio await using (var requestBody = request.Body) { using var kernel = CreateKernel(); + using var streamReader = new StreamReader(requestBody); - var body = await new StreamReader(requestBody).ReadToEndAsync(); + var body = await streamReader.ReadToEndAsync(); var bundle = JsonDocument.Parse(body).RootElement; - var commandEnvelopes = ReadCommands(bundle).ToList(); + var commandEnvelopes = ReadCommands(bundle); foreach (var commandEnvelope in commandEnvelopes) { From e00e11d934bce941d1b72dfba82e01ac687ff110 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 May 2024 13:39:40 -0700 Subject: [PATCH 3/3] CORS fixes --- src/Microsoft.TryDotNet/Program.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index 7ffc31c72..f88350fc7 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -54,7 +54,7 @@ public static async Task CreateWebApplicationAsync(WebApplicatio builder.Services.AddCors( opts => { - opts.AddPolicy("trydotnet", + opts.AddDefaultPolicy( policy => { policy @@ -108,12 +108,14 @@ public static async Task CreateWebApplicationAsync(WebApplicatio CSharpProjectKernel.RegisterEventsAndCommands(); var app = builder.Build(); - - app.UseCors("trydotnet"); + + app.UseCors(); + app.UseBlazorFrameworkFiles("/wasmrunner"); - app.UsePeaky(); app.UseStaticFiles(); app.MapFallbackToFile("/wasmrunner/{*path:nonfile}", "wasmrunner/index.html"); + + app.UsePeaky(); app.UseResponseCompression(); Func> editorHandler = async (request, response) =>