title: (Nginx) + Gunicorn + Flask + Bokeh on Azure with AD
body: <p>(Apologies: I'm a webapp novice.)</p>
  
  <p>REQUIREMENTS: </p>
  
  <ul>
  <li>Azure Application Services Web App</li>
  <li>Need Azure AD to authenticate users</li>
  <li>Python Bokeh app to display data webapp once user is authenticated</li>
  </ul>
  
  <p>ATTEMPT:</p>
  
  <ul>
  <li>I tried wrapping a Flask app around Bokeh using <a href="https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py" rel="nofollow noreferrer">this example</a>  After many iterations I can't get all traffic to flow to bokeh after authenticating.  I've tried flask redirect(), and my latest iteration involves using requests' get() from the example in the link.</li>
  </ul>
  
  <p>.</p>
  
  <pre><code>...
  from requests import get
  ...
  @app.route('/')
  def bkapp_page():
      script = server_document('https://myapp.azurewebsites.net/bkapp')
      return render_template("embed.html", script=script, template="Flask")
  
  @app.route('/bkapp', defaults={'path': ''})
  @app.route('/bkapp/&lt;path:path&gt;")
  def bkapp(path):
      return get(f'http://localhost:5006/bkapp/{path}').content
  ...
  </code></pre>
  
  <p>PROBLEM:
   - Despite many iterations, I can't get the template bokeh renders (which points to javascript the server serves) to point to a path that successfully renders the page.  The best I have done is to get the /bkapp endpoint to not give me a 404 error. 
   - Python Bokeh runs on port 5006 and flask is running on 8000.  I need to forward all traffic destined to bokeh (after authentication) to bokeh through flask. (Azure App Services appear to only allow one open port unless you customize a container, which I'd like to avoid.)</p>
  
  <p>ALTERNATIVES?:</p>
  
  <ul>
  <li>Sit nginx in front of gunicorn and use a 'reverse proxy' to send all traffic to bokeh.  (Can I do this securely?) But I will have to create a custom container.  I'd rather do this with just gunicorn + flask + bokeh, if possible.</li>
  <li>Feel free to propose anything else.  I'd like to use just gunicorn + flask + bokeh, but if I need a different method, I'll result to that.
  Thanks!</li>
  </ul>