@neoncontrails wrote:
I have a handful of Dash SPAs that are running on different ports. I would like to map those applications to URLs on the same domain, e.g. by forwarding incoming GET requests for mydomain.com/app1 => localhost:8050, mydomain.com/app2 => localhost:8051, etc.
I once used nginx for this and as I recall it was pretty straightforward, but I’d prefer not to burden my colleagues with a non-Python dependency (which, as I recall, requires a bit of post-install work to initialize the daemon on the correct port(s), and that sort of work isn’t really in their skill sets).
I tried setting up a rudimentary proxy server in Flask to simply pass contents of the resolved URL back to the client, e.g.:
from flask import Flask from requests import get from collections import defaultdict app = Flask(__name__) routes = { "dashapp1": "http://localhost:8888", "dashapp2": "http://localhost:8889", "dashapp3": "http://localhost:8890" } router = defaultdict(lambda: "http://localhost:8080/404", routes) @app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def proxy(path): route = router[path] return get(route).content if __name__ == '__main__': app.run(host='0.0.0.0', port=8080)This kinda works. But it only fetches the initial “Loading…” message for the proxied urls.
Which makes sense, because Dash applications are asynchronously loaded over a websocket, they’re not just static text documents. But given that’s the case, is it even possible with Flask to bind individual Dash applications to paths on a canonical hostname? (I suspect I might have to use nginx for this part of the application, but I’m hoping maybe someone out there knows of a pure Python solution to this problem.)
Posts: 2
Participants: 1