staticwebdev / blazor-starter

A starter template in C# APIs and Blazor for Azure Static Web Apps
217 stars 104 forks source link

Could not hit function API running template in VS 2022 #21

Closed dotnetnoobie closed 2 years ago

dotnetnoobie commented 2 years ago

When I created a repo from the template and then cloned it to my local machine I was not able to hit the API endpoint in the functions app.

I need to update the appsettings.Development.json file with { "BaseAddress": "http://localhost:7071/" }

Then I also needed to update the Program.cs file with var baseAddress = builder.Configuration["BaseAddress"] ?? builder.HostEnvironment.BaseAddress; builder.Services.AddScoped(_ => new HttpClient { BaseAddress = new Uri(baseAddress) }); replacing builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) })

Basically copying from the previous / older template

Then I was able to get the data from the function app when I navigated to the fetchdata page

I also needed to add the Shared project as it was not included in the solution when I opened it in VS (it was in the cloned repo, just not referenced in the solution when I opened it)

hjy1210 commented 2 years ago

@dotnetnoobie Even following your method, I still can not hit function API.

In my environment, baseAddress STILL is "http://localhost:5000" not "http://localhost:7071".

I seems that builder.Configuration["BaseAddress"] do not read data from appsettings.Development.json of Client project.

anthonychu commented 2 years ago

This should be addressed with #27. Thanks.