-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
WebAssemblyNetDebugProxyAppBuilderExtensions.cs
60 lines (56 loc) · 2.41 KB
/
WebAssemblyNetDebugProxyAppBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// 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 System.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Server;
namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// Provides infrastructure for debugging Blazor WebAssembly applications.
/// </summary>
public static class WebAssemblyNetDebugProxyAppBuilderExtensions
{
/// <summary>
/// Adds middleware needed for debugging Blazor WebAssembly applications
/// inside Chromium dev tools.
/// </summary>
public static void UseWebAssemblyDebugging(this IApplicationBuilder app)
{
app.Map("/_framework/debug", app =>
{
app.Use(async (context, next) =>
{
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();
if (requestPath == string.Empty)
{
requestPath = "/";
}
switch (requestPath)
{
case "/":
var targetPickerUi = new TargetPickerUi(debugProxyBaseUrl, devToolsHost);
await targetPickerUi.Display(context);
break;
case "/ws-proxy":
context.Response.Redirect($"{debugProxyBaseUrl}{browserUrl.PathAndQuery}");
break;
default:
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
break;
}
});
});
}
}
}