miguelgrinberg / flask-sock

Modern WebSocket support for Flask.
MIT License
274 stars 24 forks source link

Class Based Views? #16

Closed dsposito-ubtech closed 2 years ago

dsposito-ubtech commented 2 years ago

One of the benefits of class based views is easily applying logic (e.g., authentication validation) globally across all endpoints.

Is that possible with flask-sock? The following doesn't work for me - 404 not found:

import time

from flask import Flask
from flask.views import View
from flask_sock import Sock

app = Flask(__name__)
sock = Sock(app)

class RobotsView(View):
    @sock.route("/ws/robots")
    def greet(ws):
        while True:
            ws.send("hello")

            time.sleep(2)

However, I can connect to the endpoint no problem if I don't wrap the function in a class.

dsposito-ubtech commented 2 years ago

Sorry! I had a typo in my route - class-based views seems to work fine. :+1: