/// <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 debugProxyBaseUrl = await DebugProxyLauncher.EnsureLaunchedAndGetUrl(context.RequestServices); var requestPath = context.Request.Path.ToString(); if (requestPath == string.Empty) { requestPath = "/"; } // Although we could redirect for every URL we see here, we filter the allowed set // to ensure this doesn't get misused as some kind of more general redirector switch (requestPath) { case "/": case "/ws-proxy": context.Response.Redirect($"{debugProxyBaseUrl}{requestPath}{context.Request.QueryString}"); break; default: context.Response.StatusCode = (int)HttpStatusCode.NotFound; break; } }); }); }
/// <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; } }); }); }