-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Debug proxy as external tool #19767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SteveSandersonMS
merged 38 commits into
blazor-wasm
from
stevesa/debug-proxy-as-external-tool
Mar 12, 2020
Merged
Debug proxy as external tool #19767
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7ab64f9
Begin adding webassembly-debugproxy tool
SteveSandersonMS e6a58e5
Display list of debuggable pages
SteveSandersonMS c7fb7b0
Add actual ws-proxy logic
SteveSandersonMS 7763a94
Tidy up
SteveSandersonMS d938514
Use the normal port
SteveSandersonMS cfd12a8
Strip obsolete things from M.A.C.WA.Server project
SteveSandersonMS 750211f
Add project reference
SteveSandersonMS 3d147bd
Emit info about debug proxy location to bin during build
SteveSandersonMS d77044c
Produce NuGet package
SteveSandersonMS 88bfd3f
Obtain debug proxy config path in dev server
SteveSandersonMS 382c9fd
Remove project reference. Want to model this as a package dependency …
SteveSandersonMS 6f3353b
Copy actual binaries to output dir
SteveSandersonMS 88ad0f5
Revert "Copy actual binaries to output dir"
SteveSandersonMS cfa6651
Clean up build target locations
SteveSandersonMS 549e82e
Simplify: include dev server as content files
SteveSandersonMS ec13eef
Revert redundant changes
SteveSandersonMS 22132f2
Fix builds from clean state
SteveSandersonMS e7a9a87
Redirect to debug proxy
SteveSandersonMS b33a6f3
Actually launch debug proxy
SteveSandersonMS 37214f2
Fix URLs
SteveSandersonMS 88531c7
Fix launcher
SteveSandersonMS 2b3f05c
Include testassets launchsettings so it's easier to test debugging
SteveSandersonMS d2fcf1e
Determine port dynamically
SteveSandersonMS 64cbbde
Quit when parent quits
SteveSandersonMS f07fe47
Fix package layoua
SteveSandersonMS 963c6bf
Fix layout again
SteveSandersonMS d898af7
Another layout attempt
SteveSandersonMS 549e6a3
Use custom build targets to copy debug proxy binaries to output. Avoi…
SteveSandersonMS 2f12529
Make it skippable if desired
SteveSandersonMS a1c585c
CR: Use Process.Exited event
SteveSandersonMS 1354201
CR: Clean up
SteveSandersonMS 9f25b0b
Update src/Components/WebAssembly/DebugProxy/src/Startup.cs
SteveSandersonMS 952f7c5
Update src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs
SteveSandersonMS 5e32dc8
CR: License header
SteveSandersonMS 92131da
CR: Detect application startup when it says "Application started"
SteveSandersonMS dbe960d
CR: Just use Assembly.Location
SteveSandersonMS 8580a77
Fix typo
SteveSandersonMS b031b74
Tidy
SteveSandersonMS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Components/WebAssembly/DebugProxy/src/DebugProxyOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.WebAssembly.DebugProxy | ||
| { | ||
| public class DebugProxyOptions | ||
| { | ||
| public string BrowserHost { get; set; } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
.../WebAssembly/DebugProxy/src/Microsoft.AspNetCore.Components.WebAssembly.DebugProxy.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
| <OutputType>Exe</OutputType> | ||
| <PackageId>Microsoft.AspNetCore.Components.WebAssembly.DebugProxy</PackageId> | ||
| <IsShippingPackage>true</IsShippingPackage> | ||
| <HasReferenceAssembly>false</HasReferenceAssembly> | ||
| <Description>Debug proxy for use when building Blazor applications.</Description> | ||
| <!-- Set this to false because assemblies should not reference this assembly directly, (except for tests, of course). --> | ||
| <IsProjectReferenceProvider>false</IsProjectReferenceProvider> | ||
|
|
||
| <!-- This is so that we add the FrameworkReference to Microsoft.AspNetCore.App --> | ||
| <UseLatestAspNetCoreReference>true</UseLatestAspNetCoreReference> | ||
| <MicrosoftAspNetCoreAppVersion>3.1.0</MicrosoftAspNetCoreAppVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Reference Include="Microsoft.Extensions.CommandLineUtils.Sources" /> | ||
|
|
||
| <!-- Dependencies of ws-proxy sources --> | ||
| <Reference Include="Newtonsoft.Json" /> | ||
| <Reference Include="Mono.Cecil" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../MonoDebugProxy/ws-proxy/DevToolsProxy.cs → .../MonoDebugProxy/ws-proxy/DevToolsProxy.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| using System; | ||
| using System; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Newtonsoft.Json.Linq; | ||
|
|
||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.Extensions.CommandLineUtils; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.WebAssembly.DebugProxy | ||
| { | ||
| public class Program | ||
| { | ||
| static int Main(string[] args) | ||
| { | ||
| var app = new CommandLineApplication(throwOnUnexpectedArg: false) | ||
| { | ||
| Name = "webassembly-debugproxy" | ||
| }; | ||
| app.HelpOption("-?|-h|--help"); | ||
|
|
||
| var browserHostOption = new CommandOption("-b|--browser-host", CommandOptionType.SingleValue) | ||
| { | ||
| Description = "Host on which the browser is listening for debug connections. Example: http://localhost:9300" | ||
| }; | ||
|
|
||
| var ownerPidOption = new CommandOption("-op|--owner-pid", CommandOptionType.SingleValue) | ||
| { | ||
| Description = "ID of the owner process. The debug proxy will shut down if this process exits." | ||
| }; | ||
|
|
||
| app.Options.Add(browserHostOption); | ||
| app.Options.Add(ownerPidOption); | ||
|
|
||
| app.OnExecute(() => | ||
| { | ||
| var host = Host.CreateDefaultBuilder(args) | ||
| .ConfigureAppConfiguration((hostingContext, config) => | ||
| { | ||
| config.AddCommandLine(args); | ||
| }) | ||
| .ConfigureWebHostDefaults(webBuilder => | ||
| { | ||
| webBuilder.UseStartup<Startup>(); | ||
|
|
||
| // By default we bind to a dyamic port | ||
| // This can be overridden using an option like "--urls http://localhost:9500" | ||
| webBuilder.UseUrls("http://127.0.0.1:0"); | ||
| }) | ||
| .ConfigureServices(serviceCollection => | ||
| { | ||
| serviceCollection.AddSingleton(new DebugProxyOptions | ||
| { | ||
| BrowserHost = browserHostOption.HasValue() | ||
| ? browserHostOption.Value() | ||
| : "http://127.0.0.1:9222", | ||
| }); | ||
| }) | ||
| .Build(); | ||
|
|
||
| if (ownerPidOption.HasValue()) | ||
| { | ||
| var ownerProcess = Process.GetProcessById(int.Parse(ownerPidOption.Value())); | ||
| ownerProcess.EnableRaisingEvents = true; | ||
| ownerProcess.Exited += async (sender, eventArgs) => | ||
| { | ||
| Console.WriteLine("Exiting because parent process has exited"); | ||
| await host.StopAsync(); | ||
| }; | ||
| } | ||
|
|
||
| host.Run(); | ||
|
|
||
| return 0; | ||
| }); | ||
|
|
||
| try | ||
| { | ||
| return app.Execute(args); | ||
| } | ||
| catch (CommandParsingException cex) | ||
| { | ||
| app.Error.WriteLine(cex.Message); | ||
| app.ShowHelp(); | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Net; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
| using WebAssembly.Net.Debugging; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.WebAssembly.DebugProxy | ||
| { | ||
| public class Startup | ||
| { | ||
| public void Configure(IApplicationBuilder app, DebugProxyOptions debugProxyOptions) | ||
| { | ||
| app.UseDeveloperExceptionPage(); | ||
| app.UseWebSockets(); | ||
| app.UseRouting(); | ||
|
|
||
| app.UseEndpoints(endpoints => | ||
| { | ||
| // At the homepage, we check whether we can uniquely identify the target tab | ||
| // - If yes, we redirect directly to the debug tools, proxying to that tab | ||
| // - If no, we present a list of available tabs for the user to pick from | ||
| endpoints.MapGet("/", new TargetPickerUi(debugProxyOptions).Display); | ||
|
|
||
| // At this URL, we wire up the actual WebAssembly proxy | ||
| endpoints.MapGet("/ws-proxy", async (context) => | ||
| { | ||
| if (!context.WebSockets.IsWebSocketRequest) | ||
| { | ||
| context.Response.StatusCode = (int)HttpStatusCode.BadRequest; | ||
| return; | ||
| } | ||
|
|
||
| var loggerFactory = context.RequestServices.GetRequiredService<ILoggerFactory>(); | ||
| var browserUri = new Uri(context.Request.Query["browser"]); | ||
| var ideSocket = await context.WebSockets.AcceptWebSocketAsync(); | ||
| await new MonoProxy(loggerFactory).Run(browserUri, ideSocket); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseExceptionHandler?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why. The developer exception page provides useful diagnostic info, and this is a development-time feature only.