Skip to content

Debug toolbar doesn't works through browserify in a Docker Container #937

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

Open
SalahAdDin opened this issue Apr 30, 2017 · 9 comments
Open

Comments

@SalahAdDin
Copy link

I'm using debug-toolbar for debug my project but i have a problem using it through browserify.

This is the normal behaviour:
seleccion_333
As you can see debug-toolbar is working behind port 3000 without problems.

I had the problem with normal port, but i solved it like people said:

INTERNAL_IPS = ['::1', '172.18.0.1']
# Modify second value accord your Docker configuration:
#    docker inspect uzman_web_1 | grep -e '"Gateway"'

And the result is correct:
seleccion_331

But through browserify it doesn't works:
seleccion_332

Why? Can anyone help to me?

@SalahAdDin SalahAdDin changed the title Debug toolbar doesn't works through browserify in a Docker Container Debug toolbar doesn't works through browserify in a Docker Container Apr 30, 2017
@matthiask
Copy link
Member

I'd try overriding SHOW_TOOLBAR_CALLBACK with a version that always returns True during development. Maybe that's sufficient?

@SalahAdDin
Copy link
Author

which code did you use?

@matthiask
Copy link
Member

I didn't, it was just a suggestion.

Something like:

# app/utils.py
from django.conf import settings
def show_toolbar(request):
    return bool(settings.DEBUG)

and

# app/settings.py
SHOW_TOOLBAR_CALLBACK = 'yourapp.utils.show_toolbar'

I'm not saying that's a good idea though -- the restrictions are there for a reason, and if ever the Debug Toolbar would be visible to arbitrary visitors you'd be exposing lots and lots of information about your setup. You should be really really careful.

@SalahAdDin
Copy link
Author

But this behaviour is very strange, i mean, in local environmet (not docker), debug-toolbar works through browserify without need use any other function.

Why have we use this little function for make work it?

@hyshka
Copy link

hyshka commented Jul 11, 2017

I get the same behavior through BrowserSync inside of a Docker container. Overriding the SHOW_TOOLBAR_CALLBACK function is a valid workaround for me.

@japrogramer
Copy link

japrogramer commented Aug 16, 2017

You can still see the debug panel in a docker container if you set up middleware to check /proc/net/arp
for new ips on every new request, than appending that ip addr as a set into INTERNAL_IPS.

@SalahAdDin
Copy link
Author

@japrogramer how can it set up the middlerware in these way?

@japrogramer
Copy link

japrogramer commented Aug 17, 2017

like this, you might need to refresh the page for the first time landing on your site. Than after, DDT will be visible.

class arpMiddleware(object):
    def __init__(self, get_response):
        self.get_response = get_response
        # One-time configuration and initialization.

    def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.
        with open('/proc/net/arp') as arp:
            for line in arp:
                fields = line.split()
                if any('eth' in s for s in fields):
                    from django.conf import settings
                    settings.INTERNAL_IPS = list(set(settings.INTERNAL_IPS + [fields[0]]))
                if any('eth0' in s for s in fields):
                    print('DJANGO DEBUG TOOLBAR ___ OK')

        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.

        return response

@tim-schilling
Copy link
Member

Is this still an issue when using the following in your settings?

if DEBUG:
    import socket  # only if you haven't already imported this
    hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
    INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]

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

5 participants