Add bridge core

This commit is contained in:
Ceda EI 2020-12-21 02:16:30 +05:30
parent 4e46823ce8
commit a2941d5607
1 changed files with 35 additions and 0 deletions

35
app.py Normal file
View 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)