Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aspire doesn't replace http client Uri with actual address in blazor webassembly standalone app because it don't have appsettings.json #4785

Open
Regestea opened this issue Jul 3, 2024 · 3 comments
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Comments

@Regestea
Copy link

Regestea commented Jul 3, 2024

Describe the bug

i referenced the blazor project to Aspire app host so this is my aspire app host code

using AnswerMe.Aspire.AppHost;
    
    var builder = DistributedApplication.CreateBuilder(args);
    
    var identityServerDb=builder.AddPostgres("identityserver", password: builder.CreateStablePassword("AnswerMeDB-password"))
        .WithDataVolume()
        .WithPgAdmin()
        .AddDatabase("IdentityServerDb");
    
    var identityServerApi = builder.AddProject<Projects.IdentityServer_Api>("identityserverapi")
        .WithReference(identityServerDb);
    
    var client = builder.AddProject<Projects.AnswerMe_Client>("answermeclient")
        .WithReference(identityServerApi);
    
    builder. Build().Run();

and this is my blazor code to add HTTP client

builder.Services.AddHttpClient(nameof(HttpClients.IdentityServer),
    client => { client.BaseAddress = new("http://identityserverapi"); });

so as you can see in the result it doesn't replace the http://identityserverapi with the actual address
file

and also i found the builder.Configuration.GetConnectionString("identityserverapi"); doesn't work because we don't have appsettings.json in blazor wasm so i think Aspire doesn't work fo the blazor wasm

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jul 3, 2024
@Regestea Regestea changed the title Aspire doesn't replace http client Uri with actual address in blazor webassembly standalone app Aspire doesn't replace http client Uri with actual address in blazor webassembly standalone app because it don't have appsettings.json Jul 4, 2024
@yarseyah
Copy link

yarseyah commented Jul 5, 2024

Have you added builder.AddServiceDefaults() and app.MapDefaultEndpoints() to ensure the service discovery is included in your web application?

Service discovery doesn't work on the Wasm side, you need to look into Yarp on the web-server side of the Blazor solution and redirect to the API.

@Regestea
Copy link
Author

Regestea commented Jul 5, 2024

@yarseyah I tried to add builder.AddServiceDefaults() in Wasm project program.cs file but it gave me a lot of error, and also we don't have app in Blazor Web assembly standalone so I can't use app.MapDefaultEndpoints()and also I take looked at builder.Configuration of my blazor project and it's almost empty
image

@yarseyah
Copy link

yarseyah commented Jul 5, 2024

I'm not sure there are any Aspire components that make sense for the Blazor Wasm. You can add service discovery, etc., to the Blazor Server, but your client is entirely standalone—you want to send your API calls to the server and have the server, via Yarp, redirect your requests to the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

No branches or pull requests

2 participants