It would be nice if the app and request context were available when the handler gets called. Here's an alternative implementation of SocketMiddleware which does that:
def __call__(self, environ, start_response):
path = environ['PATH_INFO']
if path in self.ws.url_map:
handler = self.ws.url_map[path]
websocket = environ['wsgi.websocket']
with app.app_context():
with current_app.request_context(environ):
handler(websocket)
else:
return self.app(environ, start_response)
This presumes that app (your Flask app) and current_app are imported from flask.
It would be nice if the app and request context were available when the handler gets called. Here's an alternative implementation of SocketMiddleware which does that:
This presumes that app (your Flask app) and current_app are imported from flask.