Fixing cors issue
This commit is contained in:
parent
9a4b935058
commit
0c2b5f30a8
@ -7,6 +7,7 @@ import requests
|
|||||||
from quart import jsonify, make_response, Quart, render_template, request, flash, redirect, url_for
|
from quart import jsonify, make_response, Quart, render_template, request, flash, redirect, url_for
|
||||||
from quart import Quart
|
from quart import Quart
|
||||||
from quart_cors import cors
|
from quart_cors import cors
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ from os.path import isfile, join
|
|||||||
|
|
||||||
|
|
||||||
app = Quart(__name__)
|
app = Quart(__name__)
|
||||||
|
app.clients = set()
|
||||||
app = cors(app, allow_origin="*")
|
app = cors(app, allow_origin="*")
|
||||||
|
|
||||||
|
|
||||||
@ -669,6 +671,7 @@ class ServerSentEvent:
|
|||||||
return message.encode('utf-8')
|
return message.encode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET'])
|
@app.route('/', methods=['GET'])
|
||||||
async def index():
|
async def index():
|
||||||
return await render_template('index.html')
|
return await render_template('index.html')
|
||||||
@ -676,21 +679,16 @@ async def index():
|
|||||||
|
|
||||||
@app.route('/', methods=['POST'])
|
@app.route('/', methods=['POST'])
|
||||||
async def broadcast():
|
async def broadcast():
|
||||||
signature = request.headers.get('Signature')
|
|
||||||
data = await request.get_json()
|
data = await request.get_json()
|
||||||
if verify_signature(signature.encode(), sse_pubKey, data['message'].encode()):
|
for queue in app.clients:
|
||||||
for queue in app.clients:
|
await queue.put(data['message'])
|
||||||
await queue.put(data['message'])
|
return jsonify(True)
|
||||||
return jsonify(True)
|
|
||||||
else:
|
|
||||||
return jsonify(False)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/sse')
|
@app.route('/sse')
|
||||||
async def sse():
|
async def sse():
|
||||||
queue = asyncio.Queue()
|
queue = asyncio.Queue()
|
||||||
app.clients.add(queue)
|
app.clients.add(queue)
|
||||||
|
|
||||||
async def send_events():
|
async def send_events():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -711,5 +709,6 @@ async def sse():
|
|||||||
response.timeout = None
|
response.timeout = None
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True,host='0.0.0.0', port=5009)
|
app.run(debug=True,host='0.0.0.0', port=5009)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user