Program.cs 720 B

123456789101112131415161718192021222324
  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("http://swc-server");
  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. #endif
  17. return http;
  18. });
  19. await builder.Build().RunAsync();