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

Subdomains support #194

Open
rimvislt opened this issue Dec 6, 2022 · 2 comments
Open

Subdomains support #194

rimvislt opened this issue Dec 6, 2022 · 2 comments

Comments

@rimvislt
Copy link

rimvislt commented Dec 6, 2022

I have an issue with subdomain support. It seems that debug toolbar is always loading on the main domain but not the subdomains.

For example, if I have test.com, admin.test.com, and user.test.com. When I go to admin.test.com or user.test.com debug toolbar is loading all js, styles etc from test.com and if test.com is blocked it is not loading anything at all.

What will be good is that if I go to user.test.com it will load everything from it. If I go to admin.test.com it will load from it and when I go to test.com it will load from it.

I can work on pr for this just not sure what should be changed to support it and where?

@macnewbold
Copy link
Contributor

I may not be understanding exactly what you're seeing, but I regularly use this on a subdomain, and haven't run into the issue. In my case trying to load things from the root domain without using the subdomain would utterly fail, so I think it's working correctly. But if you're still seeing the issue and interested in working on a solution, let us know. I'll leave this open for now, and if not, will probably close it out later. Thanks!

@samuelhwilliams
Copy link
Contributor

samuelhwilliams commented Jun 5, 2024

I have the same issue as OP. I think this is a case where the Flask app is configured with eg SERVER_NAME=app.localhost, then all routes are served on subdomains using Flask's subdomain_matching and blueprints/routes configured on a subdomain. eg flask_app.register_blueprint(app_blueprint, subdomain='flask'). So then you only have routing to flask.app.localhost, but flask_debugtoolbar generates all its static URLs using SERVER_NAME and there's no way to tell it to serve instead on flask.app.localhost.

Hopefully that makes sense ... but can try to make a minimal code example if needed.

If, in my flask app setup, I add the following code snippet (effectively duplicating from DebugToolbarExtension.init_app the URL rules onto each subdomain), then it lets Flask serve flask-debugtoolbar's static assets from subdomains. But flask-debugtoolbar would need to stop generating external URLs for them to be routed correctly. At the moment debugtoolbar uses url_for to generate the URLs, which include the SERVER_NAME by default (ie root domain not the subdomain of the associated request). I think.

      for subdomain in [...]:
        flask_app.add_url_rule(
            "/_debug_toolbar/static/<path:filename>",
            endpoint="_debug_toolbar.static",
            subdomain=subdomain,
            view_func=toolbar.send_static_file,
        )

TL;DR - can we pass Flask-DebugToolbar a list of subdomains to serve static assets from, and can Flask-DebugToolbar link to static assets using either: relative URLs, URLs that match the subdomain of the request being handled, or a specifically-configured subdomain?

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

No branches or pull requests

3 participants