Reputation: 61
When I run my local application with flask-socketio
I can access session using from flask import session
, but when I run it with gunicorn on server (gunicorn --worker-class eventlet -w 1 app:app
) it return me session.keys()
as Array[0].
How could I fix it to establish this local-proxy with session on server?
Thanks
from flask import Flask, render_template, session, request
from flask_socketio import SocketIO, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@app.before_request
def before_request():
session['key_1'] = 'Hello,'
session['key_2'] = 'World'
@app.route('/')
def index():
return render_template('index.html')
@socketio.on('connect', namespace='/')
def socket_connect():
session_keys = session.keys()
emit('connect response', {
'session_keys': session_keys
})
@socketio.on('disconnect', namespace='/')
def socket_disconnect():
print('Client disconnected', request.sid)
if __name__ == '__main__':
socketio.run(app)
Upvotes: 2
Views: 3162
Reputation: 61
I found a solution. Session was dissapearing and could not be shared to socketio, because I added redirect page rules on cloudflare for my domain. When I changed Forwarding type of all rules to 302 - Temporary everything worked well.
Upvotes: 2