route lms socket through lms api path

This commit is contained in:
2026-07-08 10:07:43 +09:00
parent 326fe50370
commit a1bc61417e
3 changed files with 16 additions and 4 deletions
+5 -3
View File
@@ -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']
})
+7
View File
@@ -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'
@@ -45,6 +45,7 @@ type UseQaChatOptions = {
weekNumber: number
apiBaseUrl: string
socketBaseUrl: string
socketPath: string
getFreshAccessToken: () => Promise<string>
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) {