I wrote this simple flask-socketio code:
from flask import Flask
from flask_socketio import SocketIO, send
app = Flask(__name__)
app.config['SECRET_KEY'] = 'mysecret'
socketio = SocketIO(app)
@socketio.on('message')
def handle_message(msg):
print 'Message:' + msg
send(msg, broadcast=True)
if __name__ == '__main__':
socketio.run(app)
When I see chrome network analyzing, I can see the "Access-Control-Allow-Origin" value as null
.
According to Flask-socketio
documentation: (See API Reference
@ http://flask-socketio.readthedocs.io/en/latest/)
Parameters:
...
cors_allowed_origins – List of origins that are allowed to connect to this server. All origins are allowed by default.
Another suggestion I found on searching is using flask-CORS
:
app.config['SECRET_KEY'] = 'mysecret'
cors = CORS(app)
socketio = SocketIO(app)
I get the same result.
What is a way to allow Cross-Origin requests with flask-socketio?
Thanks in advance.
Below solve it for me. Interaction from Angular app.
socketio = SocketIO(app, cors_allowed_origins="*")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With