You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
using Aspire.Hosting.Lifecycle;
|
|
|
|
namespace eShopOnAbp.AppHost;
|
|
|
|
internal static class Extensions
|
|
{
|
|
/// <summary>
|
|
/// Adds a hook to set the ASPNETCORE_FORWARDEDHEADERS_ENABLED environment variable to true for all projects in the application.
|
|
/// </summary>
|
|
public static IDistributedApplicationBuilder AddForwardedHeaders(this IDistributedApplicationBuilder builder)
|
|
{
|
|
builder.Services.TryAddLifecycleHook<AddForwardHeadersHook>();
|
|
return builder;
|
|
}
|
|
|
|
private class AddForwardHeadersHook : IDistributedApplicationLifecycleHook
|
|
{
|
|
public Task BeforeStartAsync(DistributedApplicationModel appModel, CancellationToken cancellationToken = default)
|
|
{
|
|
foreach (var p in appModel.GetProjectResources())
|
|
{
|
|
p.Annotations.Add(new EnvironmentCallbackAnnotation(context =>
|
|
{
|
|
context.EnvironmentVariables["ASPNETCORE_FORWARDEDHEADERS_ENABLED"] = "true";
|
|
}));
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|