docs icon indicating copy to clipboard operation
docs copied to clipboard

Local Docker deployment API call falls

Open mrochon opened this issue 1 year ago • 3 comments

When I deploy as per this tutorial to Docker, the web app runs fine but the call to the API fails with

HttpRequestException: Connection refused (webapi:51443)

In the web app I have. WebApiBaseAddress resolves to http://webapi

Code _apiBaseUrl = Environment.GetEnvironmentVariable("WebApiBaseAddress") ?? "http://api"; var http = new HttpClient(); ViewBag.weather = await http.GetStringAsync($"{_apiBaseUrl}/weatherforecast");

I am able to reach https://localhost:51443/swagger from the browser though (and call the GET api as well)

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

mrochon avatar Sep 15 '22 04:09 mrochon

Hi @mrochon, thanks for bringing this to our notice, we will look into this and update you on this issue accordingly.

erjain avatar Sep 15 '22 12:09 erjain

Linked to already raised issue #31143

erjain avatar Sep 15 '22 12:09 erjain

The problem seems to be caused by the templated API project using app.UseHttpRedirection(). Per docs, APIs should not be using that at all: Enforce HTTPS in ASP.NET Core. I suspect the redirect response cannot be handled by the caller anyway so it fails. If you remove that line and update the project to not reference 443, you can run it in Docker and call the API.

mrochon avatar Sep 15 '22 15:09 mrochon

Hi @mrochon, I have created a repo: https://github.com/dotnet-architecture/explore-docker and pushed the sample project after testing. Also, I have removed the app.UseHttpRedirection() in this sample, you can use it for your reference. Let me know if you need more help.

erjain avatar Oct 17 '22 11:10 erjain

The issue can be closed now.

erjain avatar Oct 27 '22 07:10 erjain

Fixed by #31925

IEvangelist avatar Oct 27 '22 12:10 IEvangelist