Skip to content

Commit 321f8a5

Browse files
committed
fix(ws): adjust WebSocket path handling for proxy scenarios to prevent connection errors
1 parent 3fabdf6 commit 321f8a5

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

www/js/fpp.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13063,16 +13063,23 @@ function startFppdWS () {
1306313063
fppdWSReconnectTimer = null;
1306413064
}
1306513065
var proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
13066-
// Keep whatever path prefix the current page is under, rather than hardcoding
13067-
// root - needed so this still reaches the right fppd when viewed through
13068-
// FPP's built-in /proxy/<ip>/ relay (etc/apache2.site), which serves another
13066+
// Keep the current page's path prefix ONLY when viewed through FPP's
13067+
// built-in /proxy/<host>/ relay (etc/apache2.site), which serves another
1306913068
// FPP's pages under a path prefix instead of at the root. A plain '/fppdws'
13070-
// here connects to THIS Apache's own fppd instead of the one being proxied
13069+
// there connects to THIS Apache's own fppd instead of the one being proxied
1307113070
// to; mod_proxy_html can't fix this the way it rewrites static markup,
1307213071
// since this URL is only ever built at runtime in the browser. The /proxy/
1307313072
// Directory block's own WebSocket-upgrade rule already relays a prefixed
1307413073
// path (e.g. /proxy/<ip>/fppdws) correctly - it just never receives one.
13075-
var pathPrefix = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1);
13074+
//
13075+
// Anywhere else the prefix has to be dropped: fppd registers the socket at
13076+
// the root (WS_PATH_ADD("/fppdws") in src/StatusWebSocket.cpp) and Apache
13077+
// only ProxyPasses /fppdws, so a page living in a subdirectory - /api/ (the
13078+
// API docs) or /wled/ - asked for ws://<host>/api/fppdws, which nothing
13079+
// listens on. That connection was refused and then retried forever, filling
13080+
// the console with NS_ERROR_WEBSOCKET_CONNECTION_REFUSED on those pages.
13081+
var proxyPrefix = window.location.pathname.match(/^\/proxy\/[^\/]+\//);
13082+
var pathPrefix = proxyPrefix ? proxyPrefix[0] : '/';
1307613083
var url = proto + '//' + window.location.host + pathPrefix + 'fppdws';
1307713084
// Detach the socket being replaced. Belt and suspenders for the generation
1307813085
// check below: an abandoned socket is unreachable once nothing points at its

0 commit comments

Comments
 (0)