question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Daphne-Root-Path not taken in consideration in consumers URLs

See original GitHub issue

Daphne does not seem to use the Daphne-Root-Path when it computes the urls of the consumers.

I have:

  • Daphne-Root-Path set to appname
  • A web page at url r"^home" in my urls.py
  • A consumer routed at r"/ws/something" in my routing.py

And I observe that:

  • My web page is served at address /appname/home which means that Daphne is using the root-path correctly.
  • The websocket is served at /ws/something and not at /appname/ws/something which I would expect.

Indeed, if I look at the source, I can see that http_protocol.WebRequest has a root_path attribute which is used when a http answer is sent (here https://github.com/django/daphne/blob/1.3.0/daphne/http_protocol.py#L162) but there is nothing like this in ws_protocol.py.

Is this actually a bug or am I missing something?

I tested this with Daphne 1.2.0 but it seems that the issue remains on the lastest version on the repository.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ernestkahnwaldcommented, Aug 11, 2021

Any updates?

1reaction
muhammedabadcommented, Sep 20, 2017

Just to make my issue is related (please correct me if I’m wrong).

On localhost with runserver, I can reach the websocket connect function in my consumer with the following:

# Client
var ws = new WebSocket("ws://localhost:8000/chat/<user_id>/");
# Router config
route("websocket.connect", ws_connect, path=r"^/(?P<user_id>[^/]+)/$"),

On my production environment, my nginx conf for the websocket proxy looks like this:

location /ws/ {
	proxy_pass http://daphne-myapp;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
	proxy_set_header Daphne-Root-Path /ws;
	
}

I then try to connect to ws://myapp.com/<user_id>/ but the consumer connect never gets called. After changing the route to include the root path, everything appears to work as expected:

route("websocket.connect", ws_connect, path=r"^/ws/(?P<user_id>[^/]+)/$"),

If my issue is valid and related to this, what would be a suitable workaround ? I could easily create different routes to be used in development and production if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

daphne - Bountysource
Daphne does not seem to use the Daphne-Root-Path when it computes the urls of the consumers. I have: Daphne-Root-Path set to appname; A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found