I've got a setup where I want to run multiple WSGI apps on one server and use a Flask-SocketIO socketio-server for communication in one of those apps.
I've got my WSGI-apps served via gunicorn with eventlet, as is suggested by the Flask-SocketIO manual with the following command:
gunicorn --worker-class eventlet -w 1 myapp:application
This serves the apps all-right, the internal code for setup looks like this (__init__.py
):
from flask import Flask
from werkzeug.wsgi import DispatcherMiddleware
from Pyro4.utils.httpgateway import pyro_app as gateway
from myapp.extensions import socketio
from myapp.views.vue_js import vue
from config import PYRO_REGEX
def configure_blueprints(app):
app.register_blueprint(vue)
def register_extensions(app):
socketio.init_app(app)
app = Flask(__name__, instance_relative_config=True, template_folder='static', static_url_path='')
app.config.from_object('config')
configure_blueprints(app)
register_extensions(app)
# Set up WSGI application middleware to serve both the pyro httpgateway and this application
# through the same server
application = DispatcherMiddleware(gateway, {
'/app': app
})
This works as it should, but my application now has no websocket connection anymore. How can I make Flask-SocketIO work in this configuration?
The problem is that the javascript connection to the socketio server is getting a 404 error when trying to connect to /socketio.
Do I need to hand the Javascript side the subdomain of my app?
How would a connection string have to look if that's the case?
Right now my connection string looks like this: 'http://' + document.domain + ':' + location.port + '/'
on the Javascript side
PS: The reason I'm doing this is that I need to serve the Pyro4 gateway from the same domain as the rest of the application, since otherwise the browser applies same-origin-policy restrictions to my REST calls to pyro4. So if this is too convoluted, and an easier way exists to get to my end-goal, I'm also open for that.