Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions frontend/assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1680,23 +1680,43 @@
setWorkspaceView(workspaceViewDefault);
}

function resolveSocketBase() {
const base = state.API || '';
function resolveSocketEndpoint() {
const DEFAULT_PATH = '/socket.io';
const base = String(state.API || '').trim();

const buildPath = (inputPath) => {
const raw = String(inputPath || '');
const trimmed = raw.replace(/\/+$/, '');
const withLeading = trimmed.startsWith('/') ? trimmed : '/' + trimmed;
if (!withLeading || withLeading === '/') return DEFAULT_PATH;
if (withLeading.toLowerCase().endsWith('/api')) {
const prefix = withLeading.slice(0, -4);
return (prefix || '') + DEFAULT_PATH;
}
return withLeading + DEFAULT_PATH;
};

if (!base) {
return { origin: '', path: DEFAULT_PATH };
}

if (/^https?:\/\//i.test(base)) {
try {
const url = new URL(base);
return url.origin;
return { origin: url.origin, path: buildPath(url.pathname || '/') };
} catch {
return '';
return { origin: '', path: DEFAULT_PATH };
}
}
return '';

return { origin: '', path: buildPath(base) };
}

function ensureSocket() {
if (socket || !state.API) return socket;
const socketBase = resolveSocketBase();
socket = io(socketBase || undefined, {
const { origin: socketOrigin, path: socketPath } = resolveSocketEndpoint();
socket = io(socketOrigin || undefined, {
path: socketPath,
transports: ['websocket'],
auth: { token: state.TOKEN || undefined }
});
Expand Down