Created
October 25, 2020 20:42
-
-
Save dandynaufaldi/b0398a5354f6def120c46e7b3288ad3f to your computer and use it in GitHub Desktop.
Flask with SSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from flask import Flask, request | |
from flask_sse import sse | |
app = Flask(__name__) | |
app.config["REDIS_URL"] = "redis://localhost:6379" | |
app.register_blueprint(sse, url_prefix="/stream") | |
@app.route("/chat", methods=["POST"]) | |
def chat(): | |
chat = request.json | |
chat["time"] = time.strftime("%H:%M") | |
sse.publish(chat, type="chat") | |
return chat, 201 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment