I am trying to figure out how to send a constant stream of data in Flask and then read it in JavaScript.
This example is very basic because I am just trying to get it working.
Flask route:
@app.route("/gen", methods=["GET"])
def gen():
def make():
while True:
yield "Hello"
time.sleep(1)
return Response(make())
JavaScript:
<script>
const url = 'http://10.0.1.11:8001/gen';
fetch(url)
.then(function (response) {
return response;
})
.then(function (data) {
console.log(data)
})
</script>
This prints to the console log only one time and I do not see the message "Hello". What I would like to see is "Hello" printed every second. My end goal is to send json from my generator and parse it in my html document.
Thanks, Chris