Skip to content

fix: preserve baseUrl path in WebSocket URL construction#92

Merged
maximmaxim345 merged 2 commits intoSendspin:mainfrom
sanderdw:fix/preserve-baseurl-path
Apr 20, 2026
Merged

fix: preserve baseUrl path in WebSocket URL construction#92
maximmaxim345 merged 2 commits intoSendspin:mainfrom
sanderdw:fix/preserve-baseurl-path

Conversation

@sanderdw
Copy link
Copy Markdown
Contributor

Summary

The connect() method was discarding the path component of baseUrl when building the WebSocket URL, using only url.host. This breaks reverse proxy setups where Sendspin is served behind a subpath.

Fixes #91

Changes

Two small changes in connect():

  1. Support relative URLs — pass window.location.href as the base argument to new URL(), so relative paths like ./sendspin-proxy/ resolve correctly against the current page
  2. Preserve the path — include url.pathname when constructing the WebSocket URL, so proxy paths are not stripped

Before

const url = new URL(this.config.baseUrl);
this.wsUrl = `${wsProtocol}//${url.host}/sendspin`;
baseUrl WebSocket URL
http://192.168.1.100:8927 ws://192.168.1.100:8927/sendspin
https://example.com/proxy/ wss://example.com/sendspin ❌ (path lost)
./sendspin-proxy/ 💥 TypeError: Invalid URL

After

const url = new URL(this.config.baseUrl, typeof window !== "undefined" ? window.location.href : undefined);
const basePath = url.pathname.replace(/\/$/, "");
this.wsUrl = `${wsProtocol}//${url.host}${basePath}/sendspin`;
baseUrl WebSocket URL
http://192.168.1.100:8927 ws://192.168.1.100:8927/sendspin
https://example.com/proxy/ wss://example.com/proxy/sendspin
./sendspin-proxy/ (on https://ha.local/app/) wss://ha.local/app/sendspin-proxy/sendspin

Backward Compatibility

Fully backward-compatible — absolute URLs without a path still produce the same WebSocket URL as before, since pathname is / which gets stripped by the trailing slash removal.

sanderdw and others added 2 commits April 18, 2026 22:02
The connect() method was discarding the path component of baseUrl when
building the WebSocket URL, using only url.host. This breaks reverse
proxy setups where Sendspin is served behind a subpath (e.g. Home
Assistant Ingress).

Changes:
- Pass window.location.href as base to new URL() to support relative
  URLs (e.g. ./sendspin-proxy/)
- Include url.pathname when constructing the WebSocket URL so the
  proxy path is preserved

Both changes are backward-compatible: absolute URLs like
http://192.168.1.100:8927 still resolve to ws://192.168.1.100:8927/sendspin
since their pathname is /.

Fixes Sendspin#91
Copy link
Copy Markdown
Member

@maximmaxim345 maximmaxim345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @sanderdw !

@maximmaxim345 maximmaxim345 merged commit 756e859 into Sendspin:main Apr 20, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocket URL discards baseUrl path — breaks reverse proxy setups

2 participants