Add function to publish a message
This commit is contained in:
parent
f483ca924e
commit
7f843b4ecd
|
|
@ -188,16 +188,20 @@ def main():
|
||||||
t = threading.Thread( target=filler )
|
t = threading.Thread( target=filler )
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
from flask import Flask, current_app
|
from flask import Flask, current_app, request
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.debug = True
|
app.debug = True
|
||||||
|
|
||||||
@app.route('/stream')
|
@app.route('/stream')
|
||||||
def stream():
|
def stream():
|
||||||
return current_app.response_class( SseStream(uuid.uuid4()), mimetype='text/event-stream' )
|
return current_app.response_class( SseStream(uuid.uuid4()), mimetype='text/event-stream' )
|
||||||
@app.route('/')
|
@app.route('/', methods=('GET', 'POST'))
|
||||||
def index():
|
def index():
|
||||||
return "OK"
|
if request.method == 'POST':
|
||||||
|
msg = request.form['message']
|
||||||
|
SseStream.addMessage("Message", msg)
|
||||||
|
|
||||||
|
return f'<H1>SSE Example</H1><form method="post"><input type="text" name="message" placeholder="Publish me" ></input><button type="submit">Publish</button></form>'
|
||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue