After spending hours trying to figure out why gitpod shows the "Port not found" error page instead of our flask-based application's index page, the diagnosis is:
- The root cause of the problem is still unknown.
- Most likely this is caused by unexpected behavior of flask as on startup it briefly opens and closes the port and just moments later reopens it again.
- I think that the first time flask opens the port, gitpod detects that and opens the preview browser which, unfortunately, sends its request to the port just after flask closed it, which causes the browser to show the error page.
- It is possible to use
socat(or a similar tool) to fix the issue.
- To do so, instruct gitpod to ignore flask's port and open preview on some other port, i.g. 8080.
- Start your flask app and then run socat like this:
socat TCP-LISTEN:8080,fork TCP4:localhost:5000
socat (SOcket CAT) is a great tool!