diff --git a/src/FocusApp.Client/DevHttp/DevHttpClientHelperExtensions.cs b/src/FocusApp.Client/DevHttp/DevHttpClientHelperExtensions.cs index c70f9475..8ce50ada 100644 --- a/src/FocusApp.Client/DevHttp/DevHttpClientHelperExtensions.cs +++ b/src/FocusApp.Client/DevHttp/DevHttpClientHelperExtensions.cs @@ -13,31 +13,18 @@ public static class DevHttpClientHelperExtensions /// Adds the and related services to the and configures /// a named to use localhost or 10.0.2.2 and bypass certificate checking on Android. /// - /// name /// Development server port /// The IServiceCollection - /// - /// - /// https://github.com/dotnet/maui/discussions/8131 - /// - /// - /// https://gist.github.com/Eilon/49e3c5216abfa3eba81e453d45cba2d4 - /// by https://gist.github.com/Eilon - /// - /// - /// https://gist.github.com/EdCharbeneau/ed3d44d8298319c201f276de7a0580f1 - /// by https://gist.github.com/EdCharbeneau - /// - /// - public static IServiceCollection AddDevHttpClient(this IServiceCollection services, string name, int sslPort) + public static IServiceCollection AddDevHttpClient(this IServiceCollection services, int sslPort) { var devServerRootUrl = new UriBuilder("https", DevServerName, sslPort).Uri.ToString(); #if WINDOWS - services.AddHttpClient(name, client => - { - client.BaseAddress = new UriBuilder("https", DevServerName, sslPort).Uri; - }); + services.AddRefitClient() + .ConfigureHttpClient(client => + { + client.BaseAddress = new UriBuilder("https", DevServerName, sslPort).Uri; + }); return services; #endif @@ -67,6 +54,7 @@ public static IServiceCollection AddDevHttpClient(this IServiceCollection servic #endif } + // Configure the host name (Android always use 10.0.2.2, which is an alias to the host's loopback interface aka 127.0.0.1 or localhost) public static string DevServerName => #if WINDOWS "localhost"; diff --git a/src/FocusApp.Client/MauiProgram.cs b/src/FocusApp.Client/MauiProgram.cs index 4dea3696..9eea0406 100644 --- a/src/FocusApp.Client/MauiProgram.cs +++ b/src/FocusApp.Client/MauiProgram.cs @@ -74,11 +74,15 @@ private static IServiceCollection RegisterDatabaseContext(this IServiceCollectio private static IServiceCollection RegisterRefitClient(this IServiceCollection services) { - /*services - .AddRefitClient() - .ConfigureHttpClient(c => c.BaseAddress = new Uri("http://10.0.2.2:5223"));*/ - - services.AddDevHttpClient("webapi", 7282); +#if DEBUG + services.AddDevHttpClient(7282); +#else + // This should connect to server hosted api once it is deployed under https + services.AddHttpClient("webapi", client => + { + client.BaseAddress = new Uri("https://test.zenpxl.com:25565"); + }); +#endif return services; }