@Bryan, @p-himik,
I was able to host the Flask + Bokeh Server app within one Herokup app. No NGINX or Apache or any other external appliances needed.
Approach Used:
-
I configured the jinja2 template to inject CDN resource scripts instead of the Bokeh static/js that is set up by default, using a custom function to create those scripts based on the local installed Bokeh version. Perhaps this can be optimized a bit by using Bokeh Resources class.
-
From @p-himik hint, I wrapped the Flask application to run under Tornado.
-
I used the Flask framework to create an HTTP reverse-proxy server (only supports GET method at this time.) However, this worked until I started receiving Web Socket requests.
-
Finally, I created a Web Socket reverse-proxy for each connection opened by a client (browser) using Tornado web sockets. This part was the most challenging as I had to create/use multiple tools and code using the async programming approach from Tornado.
Results:
- I was expecting a bit of latency, but for my pleasant surprise redirecting the static/js resources to use CDN improved responsiveness quite a bit.
- This solution doesn’t require a second app in Heroku or build a complex reverse-proxy using Apache or NGINX.
- Where security is no a concern, it provides a frame work for development and test.
- Eases quite a bit integration concerns with the major frameworks with almost everything done on the user side in Python.
Code:
- I have this app currently running at https://safe-scrubland-67589.herokuapp.com/
- Code is at covid/app/utest at master · hmanuel1/covid · GitHub
I’m sure that I’m missing a couple of components. For example, I see in the Bokeh code support for POST, but I would like to understand how is used before I add support for it. I would like to contribute to the project, could you send me information to participate.
I would like to post the code in here, but it’s a project with several files. I see an “upload” option in this post. Please let me know where is the best way.
Thanks and keep the great work!
hmanuel1