Skip to content

Commit

Permalink
Merge branch 'main' into Lab-3-Updates-for-P6
Browse files Browse the repository at this point in the history
  • Loading branch information
jongalloway authored May 1, 2024
2 parents 460d7d9 + 52858d0 commit f175e71
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/eShop.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// Identity Providers

var idp = builder.AddKeycloakContainer("idp", tag: "23.0")
.WithExternalHttpEndpoints()
.ImportRealms("../Keycloak/data/import");

// DB Manager Apps
Expand All @@ -40,27 +41,28 @@
// Apps

var webApp = builder.AddProject<WebApp>("webapp")
.WithExternalHttpEndpoints()
.WithReference(basketApi)
.WithReference(catalogApi)
.WithReference(orderingApi)
.WithReference(idp, env: "Identity__ClientSecret");

// Inject the project URLs for Keycloak realm configuration
var webAppHttp = webApp.GetEndpoint("http");
var webAppHttps = webApp.GetEndpoint("https");
idp.WithEnvironment("WEBAPP_HTTP_CONTAINERHOST", webAppHttp);
idp.WithEnvironment("WEBAPP_HTTP", () => $"{webAppHttp.Scheme}://{webAppHttp.Host}:{webAppHttp.Port}");
if (webAppHttps.Exists)
{
idp.WithEnvironment("WEBAPP_HTTPS_CONTAINERHOST", webAppHttps);
idp.WithEnvironment("WEBAPP_HTTPS", () => $"{webAppHttps.Scheme}://{webAppHttps.Host}:{webAppHttps.Port}");
}
else
idp.WithEnvironment(context =>
{
var webAppHttp = webApp.GetEndpoint("http");
var webAppHttps = webApp.GetEndpoint("https");

var httpsEndpoint = webAppHttps.Exists ? webAppHttps : webAppHttp;

context.EnvironmentVariables["WEBAPP_HTTP_CONTAINERHOST"] = webAppHttp;
context.EnvironmentVariables["WEBAPP_HTTP"] = context.ExecutionContext.IsPublishMode ? webAppHttp : webAppHttp.Url;

// Still need to set these environment variables so the KeyCloak realm import doesn't fail
idp.WithEnvironment("WEBAPP_HTTPS_CONTAINERHOST", webAppHttp);
idp.WithEnvironment("WEBAPP_HTTPS", () => $"{webAppHttp.Scheme}://{webAppHttp.Host}:{webAppHttp.Port}");
}
context.EnvironmentVariables["WEBAPP_HTTPS_CONTAINERHOST"] = httpsEndpoint;
context.EnvironmentVariables["WEBAPP_HTTPS"] = context.ExecutionContext.IsPublishMode ? httpsEndpoint : httpsEndpoint.Url;
});

idp.WithEnvironment("ORDERINGAPI_HTTP", orderingApi.GetEndpoint("http"));

// Inject assigned URLs for Catalog API
Expand Down

0 comments on commit f175e71

Please sign in to comment.