Skip to main content

Application Routing Changes

Update Overview

The changes in behavior described here apply to Edge version 2.17.0 and later. Only native applications will be impacted. External apps will not need any modification.

Background

Internally, Edge uses a JupyterHub server to manage application servers. In connection with a major version update to JupyterHub, there is a small change to the routing requirements for native applications.

Previously, in versions earlier than 2.17.0, upon launch of a native application, a user is forwarded to the URL of their single user server at /user/<username>/<app_id>-<organization> without a trailing forward-slash /. Starting with Edge version 2.17.0, the URL where users will be forwarded will include the trailing forward-slash. Therefore, the URL will be /user/<username>/<app_id>-<organization>/.

This seemingly minor change nevertheless requires that native apps be updated to understand the new URL syntax.

How to Test Your Current Application

You can test to see if your native application is forward compatible with this change by doing the following:

  1. Launch your custom application on Edge.
  2. After the loading screen has completed, your application will be visible.
  3. In the browser URL bar, alter the path to include the trailing forward-slash. For example, if your application launched at http://edge.enthought.com/user/edge@enthought.com/myapp-myorg, replace the URL with http://edge.enthought.com/user/edge@enthought.com/myapp-myorg/.
  4. If your application behaves the same way without errors such as a 404 then your application is already compatible with future versions of Edge.

How to Upgrade Applications

Your application will need to support page retrieval at the base URL provided by the JUPYTERHUB_SERVICE_PREFIX environment variable, which is automatically provided to native application containers upon launch. Setting the base URL configuration is dependent on your native application's framework. The following are examples of how to implement this in common frameworks.

Streamlit

The application startup command should include the Streamlit flag --server.baseUrlPath with the value $JUPYTERHUB_SERVICE_PREFIX.

exec edm run -- streamlit run app.py --server.headless true --server.address=127.0.0.1 --server.port 9000 --server.baseUrlPath $JUPYTERHUB_SERVICE_PREFIX

Plotly-Dash

The Dash application object should be created with the url_base_pathname keyword argument set to the JUPYTERHUB_SERVICE_PREFIX environment variable.

flask_app = Flask(__name__)
dash_app = Dash(
server=flask_app,
url_base_pathname=os.environ.get("JUPYTERHUB_SERVICE_PREFIX", "/")
)

Panel and Bokeh

Both Panel and Bokeh support the --prefix flag when running the serve command in your startup script. This should be set to the JUPYTERHUB_SERVICE_PREFIX variable.


exec edm run -- panel serve app.py --address="127.0.0.1" --port=9000 --prefix=$JUPYTERHUB_SERVICE_PREFIX --allow-websocket-origin=* --log-level=debug

Flask Applications with React

Flask applications should support serving their root path at the path provided by the JUPYTERHUB_SERVICE_PREFIX environment variable. In addition, some React applications may need to have their routing updated to handle the trailing slash in their default DOM router root.

PREFIX = os.environ.get("JUPYTERHUB_SERVICE_PREFIX", "/")
app = Flask(
__name__,
static_url_path=PREFIX + "static",
)

@app.route(PREFIX)
def serve():
return render_template("index.html", url_prefix=PREFIX, greeting=greeting)