cutls / TheDesk

Mastodon Client for PC.
https://thedesk.top
GNU General Public License v3.0
282 stars 35 forks source link

URI to connect websocket should not contain a trailing slash #991

Closed RollMan closed 1 year ago

RollMan commented 1 year ago

Describe the bug

Initial launch or refleshing TheDesk fails to establish websocket connection due to unexpected 301 when NGINX performs reverse proxy between the client (TheDesk) and an ActivityPub instance.

To Reproduce

  1. Launch an instance of ActivityPub with gotosocial.
  2. Configure a reverse proxy by nginx towards gotosocial instance.
  3. Log in to the instance by TheDesk.
  4. Add a column of the home time line for example, wait a while by any toot is coming, and no upcoming posts are shown.
  5. Simultaneously, DevTools shows
WebSocket connection to 'wss://my_instance_domain/api/v1/streaming/?access_token=N2M1OTG2ZWMTZWRJYS0ZYJJKLWI3ZWQTOWZHMJKZNGY4ZJJH' failed: Error during WebSocket handshake: Unexpected response code: 301

Expected Behavior

TheDesk should be able to connect to the websocket endpoint successfully and conduct real-time update of toots.

I am not sure very well but the ActivityPub server requires a URI of wss://my_instance_domain/api/v1/streaming/ without a trailing slash (i.e. wss://my_instance_domain/api/v1/streaming), otherwise nginx returns 301 which causes websocket errors. I tried to put a breakpoint in bareStreaming.ts and removed the trailing slash from the variable of start, then streaming seemed work well.

Perhaps, the problem may not on the client but server should support URIs regardless it contains trailing slash or not.

Environment

# cat sites-enabled/gtsc.coppelab.net
server {
  server_name my_instance_domain;
  location / {
    # set to 127.0.0.1 instead of localhost to work around https://stackoverflow.com/a/52550758
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
  }
  client_max_body_size 40M;

  listen [::]:443 ssl ipv6only=on; # managed by Certbot
  listen 443 ssl; # managed by Certbot
  ssl_certificate /path/to/crt;
  ssl_certificate_key /path/to/key;
}

Additional context

No response

cutls commented 1 year ago

As long as Mastodon WebUI connects streaming with /, TheDesk also cannot remove / of streming url.

RollMan commented 1 year ago

Okay that would be fine. Finally I'm sharing a quick workaround I found for those who are facing the same problem; I rewrote the requested location by the rewrite directive with NGINX.

rewrite ^/api/v1/streaming/$ /api/v1/streaming break;

Thanks for the useful software!