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

Appbuilder under reverse proxy with subdomain #2258

Open
francescognn opened this issue Jul 10, 2024 · 1 comment
Open

Appbuilder under reverse proxy with subdomain #2258

francescognn opened this issue Jul 10, 2024 · 1 comment

Comments

@francescognn
Copy link

francescognn commented Jul 10, 2024

Environment

Flask-Appbuilder version:
latest

Describe the expected results

By setting APPLICATION_ROOT variable, the builder should expose all resources under the given root subpath. This is particularly convenient when running the app under reverse proxy. For instance if you need to run the app under: "mzdomain.com/myapp/", by setting APPLICATION_ROOT = "/myapp" should return all resources with that prefix.

Describe the actual results

APPLICATION_ROOT doesn't have any effect on this and urls are given in different ways in views, widgets etc...

@francescognn
Copy link
Author

francescognn commented Jul 10, 2024

I actually would like to start a PR, but how do I set up the dev environment? looks like pip req files are not there anymore. Should I use setup.py develop?
I am pretty sure this will impact most of the views and templates (i noticed url_from from flask is called directly in the templates many times) in principle in most of the get_url(_for)... the prefix should be added, or another method could be added to substitute url_for used here and there.

I am doing this in a project but we probably don't cover all the spots.
For now what we are doing is the following (not nice but it works):

class AppBuilder(...):
    @property
    def url_prefix(self):
        return self.app.config['APPLICATION_ROOT'] or ""

    @property
    def get_url_for_login(self):
        return **self.url_prefix** + url_for('%s.%s' % (self.sm.auth_view.endpoint, 'login'))

and so on...

class TamplateFilters(....):

    def safe_url_for(self, endpoint, **values):
        try:
            return **current_app.config['APPLICATION_ROOT'] +** url_for(endpoint, **values)
        except Exception:
            return None

In general looks like most of the work could be done by moving from url_for to a custom version of it with the prefix

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

No branches or pull requests

1 participant