SwcProgram.cs 815 B

12345678910111213141516171819202122232425
  1. using Microsoft.AspNetCore.Components.Web;
  2. using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
  3. using SimpleWebChat.BlazorWasm;
  4. var builder = WebAssemblyHostBuilder.CreateDefault(args);
  5. builder.RootComponents.Add<App>("#app");
  6. builder.RootComponents.Add<HeadOutlet>("head::after");
  7. builder.Services.AddScoped(sp =>
  8. {
  9. var http = new HttpClient();
  10. #if DEBUG
  11. http.BaseAddress = new Uri("https://swc-local-dev.topcl.net");
  12. #else
  13. var NavManager = sp.GetService<Microsoft.AspNetCore.Components.NavigationManager>();
  14. var ba = new Uri($"{NavManager.ToAbsoluteUri("/").GetLeftPart(UriPartial.Scheme | UriPartial.Authority)}");
  15. http.BaseAddress = ba;
  16. SimpleWebChat.BlazorWasm.Modules.GlobalModule.BasePath = NavManager.BaseUri;
  17. #endif
  18. return http;
  19. });
  20. await builder.Build().RunAsync();