Skip to content

Commit 86a0ec2

Browse files
Merge pull request #72 from CodebreakerApp/71-blazor-communication-with-gateway
71 blazor communication with gateway
2 parents dfee402 + 8120623 commit 86a0ec2

7 files changed

Lines changed: 20 additions & 147 deletions

File tree

src/CodeBreaker.Blazor.Client/Configuration/RemoteServiceDiscovery.cs

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/CodeBreaker.Blazor.Client/Program.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using BlazorApplicationInsights;
22
using Codebreaker.GameAPIs.Client;
3-
using CodeBreaker.Blazor.Client.Configuration;
43
using CodeBreaker.Blazor.Client.Contracts.Services;
54
using CodeBreaker.Blazor.Client.Extensions;
65
using CodeBreaker.Blazor.Client.Services;
@@ -10,8 +9,6 @@
109

1110
var builder = WebAssemblyHostBuilder.CreateDefault(args);
1211

13-
builder.Configuration.AddRemoteServiceDiscovery(new Uri (builder.HostEnvironment.BaseAddress));
14-
1512
builder.Services.AddFluentUIComponents();
1613

1714
builder.Services.AddLocalization();
@@ -33,14 +30,12 @@
3330
builder.Services.AddTransient<AllAuthorizationMessageHandler>();
3431

3532
builder.Services.AddHttpClient<IGamerNameSuggestionClient, GamerNameSuggestionClient>(configure =>
36-
configure.BaseAddress = new Uri("https://gateway/users/public")
37-
)
38-
.ConfigureRemoteServiceDiscovery();
33+
configure.BaseAddress = new Uri(builder.Configuration.GetRequired("UserServicePublicBaseAddress"))
34+
);
3935

4036
builder.Services.AddHttpClient<IGamesClient, GamesClient>(configure =>
41-
configure.BaseAddress = new Uri("https://gateway/games/")
37+
configure.BaseAddress = new Uri(builder.Configuration.GetRequired("GameServiceBaseAddress"))
4238
)
43-
.ConfigureRemoteServiceDiscovery()
4439
.AddHttpMessageHandler<AllAuthorizationMessageHandler>();
4540

4641
builder.Services.AddScoped<IMobileDetectorService, MobileDetectorService>();
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"DetailedErrors": true
2+
"DetailedErrors": true,
3+
"AzureAdB2C:RedirectUri": "http://localhost:5208/authentication/login-callback",
4+
"GameServiceBaseAddress": "http://localhost:5011/games",
5+
"UserServicePublicBaseAddress": "http://localhost:5011/users/public"
36
}

src/CodeBreaker.Blazor.Client/wwwroot/appsettings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"AzureAdB2C": {
33
"Authority": "https://codebreaker3000.b2clogin.com/codebreaker3000.onmicrosoft.com/B2C_1_SUSI",
44
"ClientId": "558b37b7-0a71-4463-9d3c-d74220b7e5ee",
5-
"ValidateAuthority": false
6-
}
5+
"ValidateAuthority": false,
6+
"RedirectUri": "https://blazor.codebreaker.app/authentication/login-callback"
7+
},
8+
"GameServiceBaseAddress": "https://codebreaker.cninnovation.com/games",
9+
"UserServicePublicBaseAddress": "https://codebreaker.cninnovation.com/users/public"
710
}

src/CodeBreaker.Blazor/Program.cs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CodeBreaker.Blazor.Client.Pages;
22
using Codebreaker.GameAPIs.Client;
33
using CodeBreaker.Blazor.Components;
4+
using CodeBreaker.Blazor.Client.Extensions;
45
using CodeBreaker.Blazor.Client.Services;
56
using CodeBreaker.Blazor.Client.Contracts.Services;
67
using Microsoft.FluentUI.AspNetCore.Components;
@@ -19,11 +20,11 @@
1920

2021
builder.Services.AddHttpClient<IGamerNameSuggestionClient, GamerNameSuggestionClient>(configure =>
2122
configure.BaseAddress =
22-
new Uri("https://userapis") // Utilize Aspire service discovery
23+
new Uri(builder.Configuration.GetRequired("UserServicePublicBaseAddress"))
2324
);
2425

2526
builder.Services.AddHttpClient<IGamesClient, GamesClient>(configure =>
26-
configure.BaseAddress = new Uri("https://gameapis") // Utilize Aspire service discovery
27+
configure.BaseAddress = new Uri(builder.Configuration.GetRequired("GameServiceBaseAddress"))
2728
);
2829

2930
builder.Services.AddScoped<IMobileDetectorService, MobileDetectorService>();
@@ -57,31 +58,4 @@
5758
.AddInteractiveWebAssemblyRenderMode()
5859
.AddAdditionalAssemblies(typeof(GamePage).Assembly);
5960

60-
/// <summary>
61-
/// Reads the environment variables for services and returns a mapping of service names to URLs.
62-
/// </summary>
63-
app.MapGet("/service-discovery", () =>
64-
{
65-
var serviceMapping = new Dictionary<string, string>();
66-
var environmentVariables = Environment.GetEnvironmentVariables();
67-
68-
foreach (var key in environmentVariables.Keys)
69-
{
70-
var keyText = key.ToString()!;
71-
72-
// Check if the key is a service URL (e.g. services__gameapis__http)
73-
if (keyText.StartsWith("services__"))
74-
{
75-
// Extract the service name from the key (e.g. gameapis
76-
var serviceName = keyText.Split("__")[1];
77-
78-
// Add the service name and URL to the mapping if it doesn't already exist
79-
if (!serviceMapping.ContainsKey(serviceName))
80-
serviceMapping.Add(serviceName, environmentVariables[key]!.ToString()!);
81-
}
82-
}
83-
84-
return Results.Json(serviceMapping);
85-
});
86-
8761
app.Run();
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"DetailedErrors": true
2+
"DetailedErrors": true,
3+
"GameServiceBaseAddress": "http://localhost:5011/games",
4+
"UserServicePublicBaseAddress": "http://localhost:5011/users/public"
35
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
{
2+
"GameServiceBaseAddress": "https://codebreaker.cninnovation.com/games",
3+
"UserServicePublicBaseAddress": "https://codebreaker.cninnovation.com/users/public"
24
}

0 commit comments

Comments
 (0)