diff --git a/src/Server/Startup.cs b/src/Server/Startup.cs index d41992d..d8a4d3a 100644 --- a/src/Server/Startup.cs +++ b/src/Server/Startup.cs @@ -1,10 +1,13 @@ using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.ResponseCompression; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Newtonsoft.Json.Serialization; +using System; using System.Linq; +using System.Net.Http; namespace tmp.Server { @@ -20,6 +23,21 @@ namespace tmp.Server opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat( new[] { "application/octet-stream" }); }); + + // Server Side Blazor doesn't register HttpClient by default + if (!services.Any(x => x.ServiceType == typeof(HttpClient))) + { + // Setup HttpClient for server side in a client side compatible fashion + services.AddScoped(s => + { + // Creating the URI helper needs to wait until the JS Runtime is initialized, so defer it. + var uriHelper = s.GetRequiredService(); + return new HttpClient + { + BaseAddress = new Uri(uriHelper.BaseUri) + }; + }); + } } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/src/Server/Steeltoe.Server.csproj b/src/Server/Steeltoe.Server.csproj index 9489086..5f4c6f6 100644 --- a/src/Server/Steeltoe.Server.csproj +++ b/src/Server/Steeltoe.Server.csproj @@ -12,6 +12,7 @@ +