-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathProgram.cs
More file actions
81 lines (67 loc) · 3.06 KB
/
Program.cs
File metadata and controls
81 lines (67 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Azure.Core;
using PlatformPlatform.AppGateway.ApiAggregation;
using PlatformPlatform.AppGateway.Filters;
using PlatformPlatform.AppGateway.Middleware;
using PlatformPlatform.AppGateway.Transformations;
using PlatformPlatform.SharedKernel.Configuration;
using Scalar.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
var reverseProxyBuilder = builder.Services
.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddConfigFilter<ClusterDestinationConfigFilter>()
.AddConfigFilter<ApiExplorerRouteFilter>().AddTransforms(
context => context.RequestTransforms.Add(context.Services.GetRequiredService<BlockInternalApiTransform>())
);
if (SharedInfrastructureConfiguration.IsRunningInAzure)
{
builder.Services.AddSingleton<TokenCredential>(SharedInfrastructureConfiguration.DefaultAzureCredential);
builder.Services.AddSingleton<ManagedIdentityTransform>();
builder.Services.AddSingleton<ApiVersionHeaderTransform>();
builder.Services.AddSingleton<HttpStrictTransportSecurityTransform>();
reverseProxyBuilder.AddTransforms(context =>
{
context.RequestTransforms.Add(context.Services.GetRequiredService<ManagedIdentityTransform>());
context.RequestTransforms.Add(context.Services.GetRequiredService<ApiVersionHeaderTransform>());
context.ResponseTransforms.Add(context.Services.GetRequiredService<HttpStrictTransportSecurityTransform>());
}
);
}
else
{
builder.Services.AddSingleton<SharedAccessSignatureRequestTransform>();
reverseProxyBuilder.AddTransforms(
context => context.RequestTransforms.Add(context.Services.GetRequiredService<SharedAccessSignatureRequestTransform>())
);
}
builder.AddNamedBlobStorages(("avatars-storage", "AVATARS_STORAGE_URL"));
builder.WebHost.UseKestrel(option => option.AddServerHeader = false);
builder.Services.AddHttpClient(
"AccountManagement",
client => { client.BaseAddress = new Uri(Environment.GetEnvironmentVariable("ACCOUNT_MANAGEMENT_API_URL") ?? "https://localhost:9100"); }
);
builder.Services
.AddHttpClient()
.AddHttpForwardHeaders() // Ensure the correct client IP addresses are set for downstream requests
.AddOutputCache();
builder.Services
.AddSingleton(SharedDependencyConfiguration.GetTokenSigningService())
.AddSingleton<BlockInternalApiTransform>()
.AddSingleton<AuthenticationCookieMiddleware>()
.AddScoped<ApiAggregationService>();
var app = builder.Build();
app.ApiAggregationEndpoints();
app.UseForwardedHeaders() // Enable support for proxy headers such as X-Forwarded-For and X-Forwarded-Proto. Should run before other middleware.
.UseOutputCache()
.UseMiddleware<AuthenticationCookieMiddleware>();
app.MapScalarApiReference("/openapi", options =>
{
options
.WithOpenApiRoutePattern("/openapi/v1.json")
.WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient)
.WithTitle("PlatformPlatform API")
.WithSidebar(true);
}
);
app.MapReverseProxy();
await app.RunAsync();