Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing the baseURL for ProxySupport #229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adamboutcher
Copy link

See issue - #228

This (probably terrible) change will allow you to use the env variable "MATHICS_DJANGO_URL" to support serving the files from a different BASE_URL.

This meant we could serve the application via a proxy, we were using "Open OnDemand" with a proxy configuration we couldn't change and also dynamic proxy addresses.

@@ -37,6 +37,9 @@ def get_bool_from_environment(env_var: str, default_value: str):
# Use Django's default value for ALLOWED_HOSTS.
ALLOWED_HOSTS = []

# Support changing the Base URL
BASE_URL = os.environ.get("MATHICS_DJANGO_URL", None)
Copy link
Member

@rocky rocky Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value needs to be a string type. On line 166 below, among other places, there is the use of string concatenation "+": BASE_URL+"/media".

Suggested change
BASE_URL = os.environ.get("MATHICS_DJANGO_URL", None)
BASE_URL = os.environ.get("MATHICS_DJANGO_URL", "")

Copy link
Member

@rocky rocky Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you do me a favor and try this out in a non-proxy environment with MATHICS_DJANGO_URL unset?

I wonder if the non-absolute URLs in that environment still work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value needs to be a string type. On line 166 below, among other places, there is the use of string concatenation "+": BASE_URL+"/media".

Suggested change
BASE_URL = os.environ.get("MATHICS_DJANGO_URL", None)
BASE_URL = os.environ.get("MATHICS_DJANGO_URL", "")

Ok, I'm not a python dev so but like this I'll miss... Will fix this when I get a chance.

Would you do me a favor and try this out in a non-proxy environment with MATHICS_DJANGO_URL unset?

I wonder if the non-absolute URLs in that environment still work.

I'll test it either tomorrow (Fri) or Monday.

I suspect my changes are maybe a bit harsh and I suspect might kill the about page if it's not got .html appended.

The main issue is the way browers treat relative Vs absolute URLs and how django reads the URL back in. If I could control the proxy better then I could add a rewrite line but that's contained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants