diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index c4cd1a1..252ec06 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -9,7 +9,7 @@ import Sidebar from './components/Sidebar' import PlatformLoadingOverlay from './components/PlatformLoadingOverlay' import { RunningPlatformCloseModal, SessionConfirmModal, StatusNoticeModal, WeekSwitchBlockedModal } from './components/AppStatusModals' import TitleBar from './components/TitleBar' -import { LMS_API_BASE_URL, LMS_SOCKET_BASE_URL, SELECTED_COURSE_STORAGE_KEY, launcherApiUrl } from './config/appConfig' +import { LMS_API_BASE_URL, LMS_SOCKET_ORIGIN, LMS_SOCKET_PATH, SELECTED_COURSE_STORAGE_KEY, launcherApiUrl } from './config/appConfig' import { clearStoredAuthSession, exchangeLauncherHandoff, readStoredAuthSession, refreshStoredAuthSession, storeAuthSession } from './features/auth/authSession' import type { LmsAuthSession } from './features/auth/authSession' import CourseSelectionScreen from './features/curriculum/CourseSelectionScreen' @@ -432,7 +432,8 @@ function LocalPcWorkspaceMockup({ accessToken, weekNumber, apiBaseUrl: LMS_API_BASE_URL, - socketBaseUrl: LMS_SOCKET_BASE_URL, + socketBaseUrl: LMS_SOCKET_ORIGIN, + socketPath: LMS_SOCKET_PATH, getFreshAccessToken, onTitlebarNotice }) @@ -3172,8 +3173,9 @@ export default function App(): React.JSX.Element { useEffect(() => { if (!authSession?.accessToken) return - const socket: Socket = io(LMS_SOCKET_BASE_URL, { + const socket: Socket = io(LMS_SOCKET_ORIGIN, { auth: { token: authSession.accessToken }, + path: LMS_SOCKET_PATH, transports: ['websocket', 'polling'] }) diff --git a/src/renderer/src/config/appConfig.ts b/src/renderer/src/config/appConfig.ts index b91cf46..4d8daac 100644 --- a/src/renderer/src/config/appConfig.ts +++ b/src/renderer/src/config/appConfig.ts @@ -1,5 +1,12 @@ export const LMS_API_BASE_URL = (import.meta.env.VITE_API_BASE_URL || 'http://localhost:4400/api').replace(/\/+$/, '') export const LMS_SOCKET_BASE_URL = LMS_API_BASE_URL.replace(/\/api$/, '') +const LMS_SOCKET_URL = new URL(LMS_SOCKET_BASE_URL || '/', window.location.origin) +if (LMS_SOCKET_URL.hostname === 'workspace.autonomystudio.net' && LMS_SOCKET_URL.pathname === '/') { + LMS_SOCKET_URL.pathname = '/lms-api' +} +const LMS_SOCKET_PREFIX = LMS_SOCKET_URL.pathname.replace(/\/+$/, '') +export const LMS_SOCKET_ORIGIN = LMS_SOCKET_URL.origin +export const LMS_SOCKET_PATH = `${LMS_SOCKET_PREFIX}/socket.io` export const LAUNCHER_API_BASE_URL = (import.meta.env.VITE_LAUNCHER_API_BASE_URL || 'http://localhost:4200/api').replace(/\/+$/, '') export const SELECTED_COURSE_STORAGE_KEY = 'lms-selected-course-id' diff --git a/src/renderer/src/features/workspace/useQaChat.ts b/src/renderer/src/features/workspace/useQaChat.ts index 202d50a..4df91af 100644 --- a/src/renderer/src/features/workspace/useQaChat.ts +++ b/src/renderer/src/features/workspace/useQaChat.ts @@ -45,6 +45,7 @@ type UseQaChatOptions = { weekNumber: number apiBaseUrl: string socketBaseUrl: string + socketPath: string getFreshAccessToken: () => Promise onTitlebarNotice: (title: string, tone?: 'info' | 'warning' | 'error', addToList?: boolean) => void } @@ -64,6 +65,7 @@ export function useQaChat({ weekNumber, apiBaseUrl, socketBaseUrl, + socketPath, getFreshAccessToken, onTitlebarNotice }: UseQaChatOptions) { @@ -118,6 +120,7 @@ export function useQaChat({ if (!accessToken) return const socket: Socket = io(socketBaseUrl, { auth: { token: accessToken }, + path: socketPath, transports: ['websocket', 'polling'] }) @@ -135,7 +138,7 @@ export function useQaChat({ socket.off('chat.message.created', onMessageCreated) socket.disconnect() } - }, [accessToken, onTitlebarNotice, socketBaseUrl]) + }, [accessToken, onTitlebarNotice, socketBaseUrl, socketPath]) useEffect(() => { if (!accessToken || !validChatWeek) {