Compare commits
4 Commits
505e02cc6a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a2941d5607 | |||
| 4e46823ce8 | |||
| d7015c186e | |||
| 541dea9b86 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -129,3 +129,4 @@ dmypy.json
|
|||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|
||||||
|
config.py
|
||||||
|
|||||||
35
app.py
Normal file
35
app.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from flask import Flask, jsonify, request
|
||||||
|
from flask_socketio import SocketIO, emit
|
||||||
|
import time
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config['SECRET_KEY'] = config.SECRET_KEY
|
||||||
|
socketio = SocketIO(app, **config.SOCKET_IO_CONFIG)
|
||||||
|
|
||||||
|
@app.route("/send", methods=["POST"])
|
||||||
|
def send():
|
||||||
|
"""
|
||||||
|
Bridges the message into the frontend
|
||||||
|
|
||||||
|
JSON
|
||||||
|
{
|
||||||
|
event: Name of the event to emit
|
||||||
|
data: data for the emission
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
if not request.json:
|
||||||
|
return jsonify({"success": False}), 400
|
||||||
|
try:
|
||||||
|
event = request.json["event"]
|
||||||
|
data = request.json["data"]
|
||||||
|
except KeyError:
|
||||||
|
return jsonify({"success": False}), 400
|
||||||
|
|
||||||
|
socketio.emit(event, data)
|
||||||
|
return jsonify({"success": True})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
socketio.run(app, config.HOST, config.PORT)
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Flask>=1.1
|
||||||
|
Flask-SocketIO>=5.0
|
||||||
10
sample.config.py
Normal file
10
sample.config.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
SECRET_KEY = "set this to something secret"
|
||||||
|
|
||||||
|
# Set host and port to listen on
|
||||||
|
HOST = "localhost"
|
||||||
|
PORT = 5050
|
||||||
|
|
||||||
|
# Config for SocketIO and EngineIO
|
||||||
|
SOCKET_IO_CONFIG = {
|
||||||
|
"cors_allowed_origins": "*"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user