Initial working end-to-end

This commit is contained in:
Safia Abdalla 2020-08-20 16:05:32 -07:00
parent 691910c67d
commit 302d79a347
6 changed files with 35 additions and 25 deletions

View File

@ -306,9 +306,9 @@
<Uri>https://github.com/dotnet/runtime</Uri> <Uri>https://github.com/dotnet/runtime</Uri>
<Sha>1dfd9438149f74ae11918a7b0709b8d58c61443f</Sha> <Sha>1dfd9438149f74ae11918a7b0709b8d58c61443f</Sha>
</Dependency> </Dependency>
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="5.0.0-rc.1.20414.5"> <Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="5.0.0-rc.1.20428.3">
<Uri>https://github.com/dotnet/runtime</Uri> <Uri>https://github.com/dotnet/runtime</Uri>
<Sha>6cc7cffaff2e0413ee84d9a7736f9ae1aa9a3f12</Sha> <Sha>1dfd9438149f74ae11918a7b0709b8d58c61443f</Sha>
</Dependency> </Dependency>
</ProductDependencies> </ProductDependencies>
<ToolsetDependencies> <ToolsetDependencies>

View File

@ -68,6 +68,7 @@
<MicrosoftNETCoreAppInternalPackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppInternalPackageVersion> <MicrosoftNETCoreAppInternalPackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppInternalPackageVersion>
<MicrosoftNETCoreAppRefPackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppRefPackageVersion> <MicrosoftNETCoreAppRefPackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppRefPackageVersion>
<MicrosoftNETCoreAppRuntimewinx64PackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppRuntimewinx64PackageVersion> <MicrosoftNETCoreAppRuntimewinx64PackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppRuntimewinx64PackageVersion>
<MicrosoftNETCoreBrowserDebugHostTransportPackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreBrowserDebugHostTransportPackageVersion>
<MicrosoftWin32RegistryPackageVersion>5.0.0-rc.1.20428.3</MicrosoftWin32RegistryPackageVersion> <MicrosoftWin32RegistryPackageVersion>5.0.0-rc.1.20428.3</MicrosoftWin32RegistryPackageVersion>
<MicrosoftWin32SystemEventsPackageVersion>5.0.0-rc.1.20428.3</MicrosoftWin32SystemEventsPackageVersion> <MicrosoftWin32SystemEventsPackageVersion>5.0.0-rc.1.20428.3</MicrosoftWin32SystemEventsPackageVersion>
<MicrosoftExtensionsCachingAbstractionsPackageVersion>5.0.0-rc.1.20428.3</MicrosoftExtensionsCachingAbstractionsPackageVersion> <MicrosoftExtensionsCachingAbstractionsPackageVersion>5.0.0-rc.1.20428.3</MicrosoftExtensionsCachingAbstractionsPackageVersion>

View File

@ -10,7 +10,9 @@ using System.Reflection;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -24,20 +26,20 @@ namespace Microsoft.AspNetCore.Builder
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$", RegexOptions.None, TimeSpan.FromSeconds(10)); private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$", RegexOptions.None, TimeSpan.FromSeconds(10));
private static readonly Regex ApplicationStartedRegex = new Regex(@"^\s*Application started\. Press Ctrl\+C to shut down\.$", RegexOptions.None, TimeSpan.FromSeconds(10)); private static readonly Regex ApplicationStartedRegex = new Regex(@"^\s*Application started\. Press Ctrl\+C to shut down\.$", RegexOptions.None, TimeSpan.FromSeconds(10));
public static Task<string> EnsureLaunchedAndGetUrl(IServiceProvider serviceProvider) public static Task<string> EnsureLaunchedAndGetUrl(IServiceProvider serviceProvider, string devToolsHost)
{ {
lock (LaunchLock) lock (LaunchLock)
{ {
if (LaunchedDebugProxyUrl == null) if (LaunchedDebugProxyUrl == null)
{ {
LaunchedDebugProxyUrl = LaunchAndGetUrl(serviceProvider); LaunchedDebugProxyUrl = LaunchAndGetUrl(serviceProvider, devToolsHost);
} }
return LaunchedDebugProxyUrl; return LaunchedDebugProxyUrl;
} }
} }
private static async Task<string> LaunchAndGetUrl(IServiceProvider serviceProvider) private static async Task<string> LaunchAndGetUrl(IServiceProvider serviceProvider, string devToolsHost)
{ {
var tcs = new TaskCompletionSource<string>(); var tcs = new TaskCompletionSource<string>();
@ -45,10 +47,11 @@ namespace Microsoft.AspNetCore.Builder
var executablePath = LocateDebugProxyExecutable(environment); var executablePath = LocateDebugProxyExecutable(environment);
var muxerPath = DotNetMuxer.MuxerPathOrDefault(); var muxerPath = DotNetMuxer.MuxerPathOrDefault();
var ownerPid = Process.GetCurrentProcess().Id; var ownerPid = Process.GetCurrentProcess().Id;
var processStartInfo = new ProcessStartInfo var processStartInfo = new ProcessStartInfo
{ {
FileName = muxerPath, FileName = muxerPath,
Arguments = $"exec \"{executablePath}\"", Arguments = $"exec \"{executablePath}\" --owner-pid {ownerPid} --DevToolsUrl {devToolsHost}",
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = true, RedirectStandardOutput = true,
}; };

View File

@ -12,9 +12,7 @@
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.AspNetCore.StaticFiles" /> <Reference Include="Microsoft.AspNetCore.StaticFiles" />
<Reference Include="Microsoft.NETCore.BrowserDebugHost.Transport" GeneratePathProperty="true"/> <Reference Include="Microsoft.NETCore.BrowserDebugHost.Transport" GeneratePathProperty="true" />
<!-- Dependencies needed by DebugProxy. -->
<Reference Include= "Newtonsoft.Json" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -32,12 +30,7 @@
<Target Name="IncludeDebugProxyBinariesAsContent" BeforeTargets="AssignTargetPaths"> <Target Name="IncludeDebugProxyBinariesAsContent" BeforeTargets="AssignTargetPaths">
<ItemGroup> <ItemGroup>
<DebugProxyBinaries Include="$(PkgMicrosoft_NETCore_BrowserDebugHost_Transport)\tools\$(DefaultNetCoreTargetFramework)\**" /> <DebugProxyBinaries Include="$(PkgMicrosoft_NETCore_BrowserDebugHost_Transport)\tools\$(DefaultNetCoreTargetFramework)\**" />
<Content <Content Include="@(DebugProxyBinaries)" Pack="true" PackagePath="tools\BlazorDebugProxy\%(RecursiveDir)%(FileName)%(Extension)" Link="BlazorDebugProxy\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
Include="@(DebugProxyBinaries)"
Pack="true"
PackagePath="tools\BlazorDebugProxy\%(RecursiveDir)%(FileName)%(Extension)"
Link="BlazorDebugProxy\%(RecursiveDir)%(FileName)%(Extension)"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup> </ItemGroup>
</Target> </Target>

View File

@ -23,12 +23,13 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server
IgnoreNullValues = true IgnoreNullValues = true
}; };
private readonly string BrowserHost = "http://localhost:9222"; private string _browserHost;
private string _debugProxyUrl; private string _debugProxyUrl;
public TargetPickerUi(string debugProxyUrl) public TargetPickerUi(string debugProxyUrl, string devToolsHost)
{ {
_debugProxyUrl = debugProxyUrl; _debugProxyUrl = debugProxyUrl;
_browserHost = devToolsHost;
} }
public async Task Display(HttpContext context) public async Task Display(HttpContext context)
@ -38,7 +39,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server
var request = context.Request; var request = context.Request;
var targetApplicationUrl = request.Query["url"]; var targetApplicationUrl = request.Query["url"];
var debuggerTabsListUrl = $"{BrowserHost}/json"; var debuggerTabsListUrl = $"{_browserHost}/json";
IEnumerable<BrowserTab> availableTabs; IEnumerable<BrowserTab> availableTabs;
try try
@ -137,7 +138,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server
{ {
var underlyingV8Endpoint = new Uri(tabToDebug.WebSocketDebuggerUrl); var underlyingV8Endpoint = new Uri(tabToDebug.WebSocketDebuggerUrl);
var proxyEndpoint = new Uri(_debugProxyUrl); var proxyEndpoint = new Uri(_debugProxyUrl);
var devToolsUrlAbsolute = new Uri(BrowserHost + tabToDebug.DevtoolsFrontendUrl); var devToolsUrlAbsolute = new Uri(_browserHost + tabToDebug.DevtoolsFrontendUrl);
var devToolsUrlWithProxy = $"{devToolsUrlAbsolute.Scheme}://{devToolsUrlAbsolute.Authority}{devToolsUrlAbsolute.AbsolutePath}?{underlyingV8Endpoint.Scheme}={proxyEndpoint.Authority}{underlyingV8Endpoint.PathAndQuery}"; var devToolsUrlWithProxy = $"{devToolsUrlAbsolute.Scheme}://{devToolsUrlAbsolute.Authority}{devToolsUrlAbsolute.AbsolutePath}?{underlyingV8Endpoint.Scheme}={proxyEndpoint.Authority}{underlyingV8Endpoint.PathAndQuery}";
return devToolsUrlWithProxy; return devToolsUrlWithProxy;
} }
@ -145,7 +146,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server
private string GetLaunchChromeInstructions(string targetApplicationUrl) private string GetLaunchChromeInstructions(string targetApplicationUrl)
{ {
var profilePath = Path.Combine(Path.GetTempPath(), "blazor-chrome-debug"); var profilePath = Path.Combine(Path.GetTempPath(), "blazor-chrome-debug");
var debuggerPort = new Uri(BrowserHost).Port; var debuggerPort = new Uri(_browserHost).Port;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
@ -171,7 +172,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server
private string GetLaunchEdgeInstructions(string targetApplicationUrl) private string GetLaunchEdgeInstructions(string targetApplicationUrl)
{ {
var profilePath = Path.Combine(Path.GetTempPath(), "blazor-edge-debug"); var profilePath = Path.Combine(Path.GetTempPath(), "blazor-edge-debug");
var debuggerPort = new Uri(BrowserHost).Port; var debuggerPort = new Uri(_browserHost).Port;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
@ -210,7 +211,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server
private async Task<IEnumerable<BrowserTab>> GetOpenedBrowserTabs() private async Task<IEnumerable<BrowserTab>> GetOpenedBrowserTabs()
{ {
using var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5) }; using var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
var jsonResponse = await httpClient.GetStringAsync($"{BrowserHost}/json"); var jsonResponse = await httpClient.GetStringAsync($"{_browserHost}/json");
return JsonSerializer.Deserialize<BrowserTab[]>(jsonResponse, JsonOptions); return JsonSerializer.Deserialize<BrowserTab[]>(jsonResponse, JsonOptions);
} }

View File

@ -1,7 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Net; using System.Net;
using System.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Server; using Microsoft.AspNetCore.Components.WebAssembly.Server;
namespace Microsoft.AspNetCore.Builder namespace Microsoft.AspNetCore.Builder
@ -21,7 +23,17 @@ namespace Microsoft.AspNetCore.Builder
{ {
app.Use(async (context, next) => app.Use(async (context, next) =>
{ {
var debugProxyBaseUrl = await DebugProxyLauncher.EnsureLaunchedAndGetUrl(context.RequestServices); var queryParams = HttpUtility.ParseQueryString(context.Request.QueryString.Value);
var browserParam = queryParams.Get("browser");
Uri browserUrl = null;
var devToolsHost = "http://localhost:9222";
if (browserParam != null)
{
browserUrl = new Uri(browserParam);
devToolsHost = $"http://{browserUrl.Host}:{browserUrl.Port}";
}
var debugProxyBaseUrl = await DebugProxyLauncher.EnsureLaunchedAndGetUrl(context.RequestServices, devToolsHost);
var requestPath = context.Request.Path.ToString(); var requestPath = context.Request.Path.ToString();
if (requestPath == string.Empty) if (requestPath == string.Empty)
{ {
@ -31,11 +43,11 @@ namespace Microsoft.AspNetCore.Builder
switch (requestPath) switch (requestPath)
{ {
case "/": case "/":
var targetPickerUi = new TargetPickerUi(debugProxyBaseUrl); var targetPickerUi = new TargetPickerUi(debugProxyBaseUrl, devToolsHost);
await targetPickerUi.Display(context); await targetPickerUi.Display(context);
break; break;
case "/ws-proxy": case "/ws-proxy":
context.Response.Redirect($"{debugProxyBaseUrl}{requestPath}{context.Request.QueryString}"); context.Response.Redirect($"{debugProxyBaseUrl}{browserUrl.PathAndQuery}");
break; break;
default: default:
context.Response.StatusCode = (int)HttpStatusCode.NotFound; context.Response.StatusCode = (int)HttpStatusCode.NotFound;