Skip to content

Commit

Permalink
Trimmed unneeded code and added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleypayton committed Mar 21, 2024
1 parent 324dd3c commit f08f863
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
26 changes: 7 additions & 19 deletions src/FocusApp.Client/DevHttp/DevHttpClientHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,18 @@ public static class DevHttpClientHelperExtensions
/// Adds the <see cref="IHttpClientFactory"/> and related services to the <see cref="IServiceCollection"/> and configures
/// a named <see cref="HttpClient"/> to use localhost or 10.0.2.2 and bypass certificate checking on Android.
/// </summary>
/// <param name="name">name</param>
/// <param name="sslPort">Development server port</param>
/// <returns>The IServiceCollection</returns>
/// <remarks>
/// <para>
/// https://github.com/dotnet/maui/discussions/8131
/// </para>
/// <para>
/// https://gist.github.com/Eilon/49e3c5216abfa3eba81e453d45cba2d4
/// by https://gist.github.com/Eilon
/// </para>
/// <para>
/// https://gist.github.com/EdCharbeneau/ed3d44d8298319c201f276de7a0580f1
/// by https://gist.github.com/EdCharbeneau
/// </para>
/// </remarks>
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<IAPIClient>()
.ConfigureHttpClient(client =>
{
client.BaseAddress = new UriBuilder("https", DevServerName, sslPort).Uri;
});

return services;
#endif
Expand Down Expand Up @@ -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";
Expand Down
14 changes: 9 additions & 5 deletions src/FocusApp.Client/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ private static IServiceCollection RegisterDatabaseContext(this IServiceCollectio

private static IServiceCollection RegisterRefitClient(this IServiceCollection services)
{
/*services
.AddRefitClient<IAPIClient>()
.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;
}
Expand Down

0 comments on commit f08f863

Please sign in to comment.