|
7 | 7 | using Helldivers.Sync.Configuration;
|
8 | 8 | using Helldivers.Sync.Extensions;
|
9 | 9 | using Microsoft.AspNetCore.Http.Timeouts;
|
| 10 | +using Microsoft.AspNetCore.HttpOverrides; |
10 | 11 | using Microsoft.AspNetCore.Localization;
|
11 | 12 | using System.Globalization;
|
| 13 | +using System.Net; |
12 | 14 | using System.Text.Json.Serialization;
|
| 15 | +using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork; |
13 | 16 |
|
14 | 17 | #if DEBUG
|
15 | 18 | // When generating an OpenAPI document, get-document runs with the "--applicationName" flag.
|
|
66 | 69 | });
|
67 | 70 |
|
68 | 71 | // Add and configure forwarded headers middleware
|
69 |
| -builder.Services.Configure<ForwardedHeadersOptions>(_ => { }); |
| 72 | +builder.Services.Configure<ForwardedHeadersOptions>(options => |
| 73 | +{ |
| 74 | + options.ForwardLimit = 999; |
| 75 | + options.OriginalForHeaderName = "Fly-Client-IP"; |
| 76 | + options.ForwardedHeaders = ForwardedHeaders.XForwardedFor; |
| 77 | + options.KnownNetworks.Add(new IPNetwork(IPAddress.Any, 0)); |
| 78 | + options.KnownNetworks.Add(new IPNetwork(IPAddress.IPv6Any, 0)); |
| 79 | +}); |
70 | 80 |
|
71 | 81 | // This configuration is bound here so that source generators kick in.
|
72 | 82 | builder.Services.Configure<HelldiversSyncConfiguration>(builder.Configuration.GetSection("Helldivers:Synchronization"));
|
|
144 | 154 | // Ensure web applications can access the API by setting CORS headers.
|
145 | 155 | app.UseCors();
|
146 | 156 |
|
147 |
| -// Handles rate limiting so everyone plays nice |
148 |
| -app.UseMiddleware<RateLimitMiddleware>(); |
149 |
| - |
150 | 157 | // Make sure ASP.NET Core uses the correct addresses internally rather than Fly's proxy
|
151 | 158 | app.UseForwardedHeaders();
|
152 | 159 |
|
| 160 | +// Handles rate limiting so everyone plays nice |
| 161 | +app.UseMiddleware<RateLimitMiddleware>(); |
| 162 | + |
153 | 163 | // Add middleware to timeout requests if they take too long.
|
154 | 164 | app.UseRequestTimeouts();
|
155 | 165 |
|
|
0 commit comments