Problem with a streaming endpoint through public device url

Hey there,

I have a python container running a flask webserver and set up an endpoint to stream data continuously like described in Streaming Contents — Flask Documentation (1.1.x) It works as expected if I access the webserver locally but when try through the public device url this endpoint doesn’t retrieve anything.

Could be related to balena vpn/proxy as it is in the middle between my webserver and my browser?

This is my route configured in flask:

@app.route('/stream')
@login_required
def stream():
    def eventStream():
        while True:
            # wait for source data to be available, then push it
            config.streamEvent.wait(2)
            config.streamEvent.clear()
            yield "data: {}\n\n".format(json.dumps(config.getStatus()))
    return Response(eventStream(), mimetype="text/event-stream")

Thanks in advance!
Nico

Hello,
Thanks for reaching out. In order to help you better, please do provide us with a repository link of the code that you are trying to run. Also please check if the Flask server is running on port 80. Here’s more information about the public device URL. Actions - Balena Documentation

Hi vipulgupta2048,

I cannot share it as it belongs to the company I work in. But let me know what can I do to better explain the problem.

Yes, flask is running in port 80 and I’m able to reach all the published resources and endpoints from public url. It’s just this streaming endpoint the one which doesn’t work. I get a 200 OK but data is not flowing

You could take a look here for inspiration and insert a haproxy container (:80) between your flask server and the balena-proxy. This will allow you to inspect the headers coming through and adjust/re-write them to make it work.

Hello, reaching out again. Did my colleague’s suggestion work out for you? Please let us know, thanks!

Hi @ab77, Thanks, I will give a chance to this. I’ve made some progress configuring compression in flask side but haven’t worked at all. Let’s see if a proxy in the middle can do the trick.

Yes! let us know if that works!