diff --git a/Dockerfile b/Dockerfile index 38bcd9d..d38e4ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,5 @@ RUN dotnet publish -c release -o /app --no-restore FROM mcr.microsoft.com/dotnet/aspnet:6.0 WORKDIR /app COPY --from=build /app ./ +ENV INSIDE_DOCKER=true ENTRYPOINT ["dotnet", "Server.dll"] diff --git a/server/Startup.cs b/server/Startup.cs index 5bf5af9..5917f19 100644 --- a/server/Startup.cs +++ b/server/Startup.cs @@ -1,6 +1,9 @@ +using System; +using System.Net; using System.Text.Json; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -18,6 +21,11 @@ namespace Server { // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + if ((Environment.GetEnvironmentVariable("INSIDE_DOCKER") ?? "").Length > 0) { + services.Configure(options => { + options.KnownProxies.Add(Dns.GetHostAddresses("host.docker.internal")[0]); + }); + } services.AddSingleton(); services.AddSingleton(); services.AddSingleton(NodaTime.DateTimeZoneProviders.Tzdb); @@ -34,6 +42,10 @@ namespace Server { // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + app.UseForwardedHeaders(new ForwardedHeadersOptions { + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto, + }); + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger();