2

This post has to do with deploying AirBnBs knowledge repo app.

We are hosting our knowledge-repo on a sub-route of our server - for example https://aws.our-server-uri.com/knowledge-repo and I'm running into issues with loading static content and redirects. In summary, I have no way of making the knowledge_repo Flask app aware that the app is running on a sub-route.

The issues

The first issue I ran into was making gunicorn aware of the context route in order to successfully locate the static files, which are now at /knowledge-repo/static/... and not relative to the root url. I solved this by setting the SCRIPT_NAME environment variable to /knowledge-repo before running knowledge_repo --repo . deploy. I'm including this for reference of what I've tried and for potential recommendations of a better solution.

The second issue, which is unresolved, is dynamically prepending our context route to the redirect urls generated by the web app. For example, the Home button in the top navigation bar redirects the user to the root url (https://aws.our-server-uri.com/ in our example case). I need the flask app to be aware of my context route and append /knowledge-repo/ to the page root for all links generated.

What I've tried:

I want to avoid forking and modifying this repo, so I've focussed on ways that do not involve editing the Flask app html, such as setting a <base> tag.

  • I've set the SCRIPT_NAME environment variable before deploying, but to no avail.
  • I've played around with setting some variables in a config.py which I passed using the --config config.py flag when running knowledge_repo deploy, but can't seem to find anything that does the trick.
TylerH
  • 20,799
  • 66
  • 75
  • 101
Renier Botha
  • 830
  • 1
  • 10
  • 19

1 Answers1

1

I made some code changes to make it work:

  1. Gave URL prefix to the static content.
  2. Adding URL prefix to the blueprints in flask.
  3. User URL_for with jinja templating to access the routes across HTML and JavaScript.

Here are the code changes.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Sabu George
  • 116
  • 1
  • 3
  • Thanks @sabu, will try this out. Just out of interest sake, have you tried using the `prepare_app` method in `.knowledge_repo_config.py`? Seems like our use case is exactly what that method is made for, but I can't seem to get any code I write in that method to be executed. – Renier Botha Feb 26 '18 at 06:07
  • @RenierBotha I have not used it. But how are you thinking of using it? I would like to try it out too if it can avoid changing the knowledge repo code. – Sabu George Feb 27 '18 at 05:25
  • I thought about adding a middleware to the Flask App...something like the third answer in this post: https://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes This would mean we do not have to fork the knowledge-repo, which would be a major plus. – Renier Botha Feb 27 '18 at 08:23
  • Please add the code changes to the post itself. If GitHub goes down your delete that repo then this answer loses value otherwise. – TylerH Sep 27 '21 at 20:36