Flask Socketio wont work in tunnels

from flask import Flask, render_template
from flask_socketio import SocketIO, emit
import threading

app = Flask(__name__)
socketio = SocketIO(app)

def counter_thread():
    count = 0
    while count <= 100:
        socketio.emit('counter_update', {'count': count}, namespace='/counter')
        count += 1
        socketio.sleep(1)

@app.route('/')
def index():
    return "Hello, World!"

@app.route('/time1')
def time1():
    return render_template('counter.html')

@socketio.on('connect', namespace='/counter')
def counter_connect():
    global count_thread
    if 'count_thread' not in globals():
        count_thread = socketio.start_background_task(target=counter_thread)

if __name__ == '__main__':
    socketio.run(app, port=8000)

/ works and shows hello world but /time1 shows real time counter header but not counter: number

this is the html::

<!DOCTYPE html>
<html>
<head>
    <title>Real-time Counter</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.3.1/socket.io.js"></script>
</head>
<body>
    <h1>Real-time Counter</h1>
    <div id="counter"></div>

    <script>
        var socket = io.connect('http://' + document.domain + ':' + location.port + '/counter');

        socket.on('counter_update', function(data) {
            document.getElementById('counter').innerHTML = 'Counter: ' + data.count;
        });
    </script>
</body>
</html>

on localhost it works but on the tunnel it doesnt work

Can you clarify doesn’t work? Does the page not load? Do the requests not complete succesfully?

here are some screenshots:

cloudflare tunnel of localhost:8000:

localhost:8000:
image

the counter isnt showing up or working in the cloudflare tunnel but its working in the localhost, did i setup sockets wrong or smth?

i had to send it in 2 replies cuz i can only post 1 embed per post

If you open the developer tools on the tunnel one, do you see any errors or request that fail?

nothing shows an error, the code is perfectly fine, but for some reason cloudflare cant handle socket-io? and i was wondering if there awas a way to set it up so that it would work

This has been moved to Discord