11using CodeBreaker . Blazor . Client . Pages ;
22using Codebreaker . GameAPIs . Client ;
33using CodeBreaker . Blazor . Components ;
4+ using CodeBreaker . Blazor . Client . Extensions ;
45using CodeBreaker . Blazor . Client . Services ;
56using CodeBreaker . Blazor . Client . Contracts . Services ;
67using Microsoft . FluentUI . AspNetCore . Components ;
1920
2021builder . 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
2526builder . 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
2930builder . Services . AddScoped < IMobileDetectorService , MobileDetectorService > ( ) ;
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-
8761app . Run ( ) ;
0 commit comments