Bokeh server embedded in gunicorn/Flask hosted to cloud

@p-himik @Bryan

I am trying a different architecture currently using separate Heroku dynos for the Flask app and the bokeh server.

In the following description of the problem currently faced, <masked-app-name> is a placeholder for my actual application’s name.

I can navigate to the server just fine via a web browser, e.g.

https://<masked-app-name>.herokuapp.com/

However, when I try to embed it from Flask via pull_session() within a client context manager, it fails.

Here’s the Flask app code.

from flask import Flask, render_template

from bokeh.client import pull_session
from bokeh.embed import server_session

PANEL_URL = "https://<masked-app-name>.herokuapp.com"

app = Flask(__name__)

@app.route('/', methods=['GET'])
def bkapp_page():
    with pull_session(url=PANEL_URL) as session:
        script = server_session(session_id=session.id, url=PANEL_URL)
        return render_template("embed.html", script=script, template="Flask")

The web browser for the Flask app shows 500 Server Internal Error, which is also reflected in the JavaScript console.

And the Heroku log excerpt shows the following error stack trace from Bokeh client session logic …

2020-08-28T20:07:30.436217+00:00 app[web.1]: File "/app/main.py", line 12, in bkapp_page

2020-08-28T20:07:30.436217+00:00 app[web.1]: with pull_session(url=PANEL_URL) as session:

2020-08-28T20:07:30.436217+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/bokeh/client/session.py", line 120, in pull_session

2020-08-28T20:07:30.436218+00:00 app[web.1]: session.pull()

2020-08-28T20:07:30.436218+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/bokeh/client/session.py", line 381, in pull

2020-08-28T20:07:30.436218+00:00 app[web.1]: self.check_connection_errors()

2020-08-28T20:07:30.436220+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/bokeh/client/session.py", line 367, in check_connection_errors

2020-08-28T20:07:30.436220+00:00 app[web.1]: raise OSError(f"Check your application path! The given Path is not valid: {self.url}")

2020-08-28T20:07:30.436220+00:00 app[web.1]: OSError: Check your application path! The given Path is not valid: ws://<masked-app-name>.herokuapp.com/ws

Is there a way to work around the ws:// protocol substitution in the URL to make it behave as if a user is navigating directly to the server via https?