Skip to content
Merged
Show file tree
Hide file tree
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 Mar 10, 2020
e6a58e5
Display list of debuggable pages
SteveSandersonMS Mar 10, 2020
c7fb7b0
Add actual ws-proxy logic
SteveSandersonMS Mar 10, 2020
7763a94
Tidy up
SteveSandersonMS Mar 10, 2020
d938514
Use the normal port
SteveSandersonMS Mar 10, 2020
cfd12a8
Strip obsolete things from M.A.C.WA.Server project
SteveSandersonMS Mar 10, 2020
750211f
Add project reference
SteveSandersonMS Mar 10, 2020
3d147bd
Emit info about debug proxy location to bin during build
SteveSandersonMS Mar 10, 2020
d77044c
Produce NuGet package
SteveSandersonMS Mar 10, 2020
88bfd3f
Obtain debug proxy config path in dev server
SteveSandersonMS Mar 10, 2020
382c9fd
Remove project reference. Want to model this as a package dependency …
SteveSandersonMS Mar 11, 2020
6f3353b
Copy actual binaries to output dir
SteveSandersonMS Mar 11, 2020
88ad0f5
Revert "Copy actual binaries to output dir"
SteveSandersonMS Mar 11, 2020
cfa6651
Clean up build target locations
SteveSandersonMS Mar 11, 2020
549e82e
Simplify: include dev server as content files
SteveSandersonMS Mar 11, 2020
ec13eef
Revert redundant changes
SteveSandersonMS Mar 11, 2020
22132f2
Fix builds from clean state
SteveSandersonMS Mar 11, 2020
e7a9a87
Redirect to debug proxy
SteveSandersonMS Mar 11, 2020
b33a6f3
Actually launch debug proxy
SteveSandersonMS Mar 11, 2020
37214f2
Fix URLs
SteveSandersonMS Mar 11, 2020
88531c7
Fix launcher
SteveSandersonMS Mar 11, 2020
2b3f05c
Include testassets launchsettings so it's easier to test debugging
SteveSandersonMS Mar 11, 2020
d2fcf1e
Determine port dynamically
SteveSandersonMS Mar 11, 2020
64cbbde
Quit when parent quits
SteveSandersonMS Mar 11, 2020
f07fe47
Fix package layoua
SteveSandersonMS Mar 11, 2020
963c6bf
Fix layout again
SteveSandersonMS Mar 11, 2020
d898af7
Another layout attempt
SteveSandersonMS Mar 11, 2020
549e6a3
Use custom build targets to copy debug proxy binaries to output. Avoi…
SteveSandersonMS Mar 12, 2020
2f12529
Make it skippable if desired
SteveSandersonMS Mar 12, 2020
a1c585c
CR: Use Process.Exited event
SteveSandersonMS Mar 12, 2020
1354201
CR: Clean up
SteveSandersonMS Mar 12, 2020
9f25b0b
Update src/Components/WebAssembly/DebugProxy/src/Startup.cs
SteveSandersonMS Mar 12, 2020
952f7c5
Update src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs
SteveSandersonMS Mar 12, 2020
5e32dc8
CR: License header
SteveSandersonMS Mar 12, 2020
92131da
CR: Detect application startup when it says "Application started"
SteveSandersonMS Mar 12, 2020
dbe960d
CR: Just use Assembly.Location
SteveSandersonMS Mar 12, 2020
8580a77
Fix typo
SteveSandersonMS Mar 12, 2020
b031b74
Tidy
SteveSandersonMS Mar 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Components/Blazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Authentication.Msal", "Auth
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Authentication.WebAssembly.Msal", "WebAssembly\Authentication.Msal\src\Microsoft.Authentication.WebAssembly.Msal.csproj", "{2F105FA7-74DA-4855-9D8E-818DEE1F8D43}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DebugProxy", "DebugProxy", "{96DE9B14-D81F-422E-A33A-728BFB9C153A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Components.WebAssembly.DebugProxy", "WebAssembly\DebugProxy\src\Microsoft.AspNetCore.Components.WebAssembly.DebugProxy.csproj", "{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -521,6 +525,18 @@ Global
{2F105FA7-74DA-4855-9D8E-818DEE1F8D43}.Release|x64.Build.0 = Release|Any CPU
{2F105FA7-74DA-4855-9D8E-818DEE1F8D43}.Release|x86.ActiveCfg = Release|Any CPU
{2F105FA7-74DA-4855-9D8E-818DEE1F8D43}.Release|x86.Build.0 = Release|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Debug|x64.ActiveCfg = Debug|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Debug|x64.Build.0 = Debug|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Debug|x86.ActiveCfg = Debug|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Debug|x86.Build.0 = Debug|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Release|Any CPU.Build.0 = Release|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Release|x64.ActiveCfg = Release|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Release|x64.Build.0 = Release|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Release|x86.ActiveCfg = Release|Any CPU
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -573,6 +589,8 @@ Global
{EAF50654-98ED-44BB-A120-0436EC0CD3E0} = {CBD2BB24-3EC3-4950-ABE4-8C521D258DCD}
{E4D756A7-A934-4D7F-BC6E-7B95FE4098AB} = {B29FB58D-FAE5-405E-9695-BCF93582BE9A}
{2F105FA7-74DA-4855-9D8E-818DEE1F8D43} = {E4D756A7-A934-4D7F-BC6E-7B95FE4098AB}
{96DE9B14-D81F-422E-A33A-728BFB9C153A} = {B29FB58D-FAE5-405E-9695-BCF93582BE9A}
{8BB1A8BE-F002-40A2-9B8E-439284B21C1C} = {96DE9B14-D81F-422E-A33A-728BFB9C153A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {27A36094-AA50-4FFD-ADE6-C055E391F741}
Expand Down
10 changes: 10 additions & 0 deletions src/Components/WebAssembly/DebugProxy/src/DebugProxyOptions.cs
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; }
}
}
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>
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;
Expand Down
91 changes: 91 additions & 0 deletions src/Components/WebAssembly/DebugProxy/src/Program.cs
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;
}
}
}
}
45 changes: 45 additions & 0 deletions src/Components/WebAssembly/DebugProxy/src/Startup.cs
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UseExceptionHandler?

Copy link
Member Author

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.

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);
});
});
}
}
}
Loading