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

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

Closed
dotnetnoobie opened this issue Nov 9, 2021 · 2 comments
Closed

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

dotnetnoobie opened this issue Nov 9, 2021 · 2 comments

Comments

@dotnetnoobie
Copy link

dotnetnoobie commented Nov 9, 2021

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
Copy link

hjy1210 commented Nov 27, 2021

@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
Copy link
Contributor

This should be addressed with #27. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants