ERR_CONNECTION_RESET for fastapi backend, works fine in curl

I have a simple api exposed on port 8001 below through fastapi/python. The api works fine through curl. But when I try to access it from my react frontend(http://frontend-core.fly.dev/) or postman, I get an error ERR_CONNECTION_RESET. Fly logs for backend doesnt show any activity

https://fastapi-core.fly.dev/

Reading through some of the posts here about similar errors, so far I have tried:

  • flushing out DNS entries
  • try another browser
  • ensuring internal_port in fly.toml is correct.

Would appreciate any help.

Works for me if I substitute https for http: https://frontend-core.fly.dev/

Thats odd. Did you click on the submit button? Thats when I get the connection reset error.

I get the connection request on the initial get with http.

With https, and looking at the browser, I see a request being issued to https://fastapi-core.fly.dev:8001/api/v1/ai when I push submit. The port number there is wrong.

I’m also seeing requests to wss://frontend-core.fly.dev:3000/ws. Again the port number is wrong.

Thank you for your continued help on this. The backend api is exposed on port 8001, so the request url looks correct to me. When I run the same code for backend and frontend on my local machine, everything works fine. The only difference in setup in that fly.to is using https, while on local testing I was using http.

The backend API may be running on port 8001, but presumably that is mapped (using fly.toml) to port 443 so that it can be served as https. See Fly Launch configuration (fly.toml) · Fly Docs for details.

There are two ways to proceed here. Either change your react frontend to issue requests when run in production to port 443 or use Private Networking · Fly Docs to connect directly to the backend. In that case you would indeed use port 8081, but you would use http (not https) and you would connect to fastapi-core.fly.internal instead of fastapi-core.fly.dev

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.