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 PlatformLoadingOverlay from './components/PlatformLoadingOverlay'
import { RunningPlatformCloseModal, SessionConfirmModal, StatusNoticeModal, WeekSwitchBlockedModal } from './components/AppStatusModals' import { RunningPlatformCloseModal, SessionConfirmModal, StatusNoticeModal, WeekSwitchBlockedModal } from './components/AppStatusModals'
import TitleBar from './components/TitleBar' 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 { clearStoredAuthSession, exchangeLauncherHandoff, readStoredAuthSession, refreshStoredAuthSession, storeAuthSession } from './features/auth/authSession'
import type { LmsAuthSession } from './features/auth/authSession' import type { LmsAuthSession } from './features/auth/authSession'
import CourseSelectionScreen from './features/curriculum/CourseSelectionScreen' import CourseSelectionScreen from './features/curriculum/CourseSelectionScreen'
@@ -432,7 +432,8 @@ function LocalPcWorkspaceMockup({
accessToken, accessToken,
weekNumber, weekNumber,
apiBaseUrl: LMS_API_BASE_URL, apiBaseUrl: LMS_API_BASE_URL,
socketBaseUrl: LMS_SOCKET_BASE_URL, socketBaseUrl: LMS_SOCKET_ORIGIN,
socketPath: LMS_SOCKET_PATH,
getFreshAccessToken, getFreshAccessToken,
onTitlebarNotice onTitlebarNotice
}) })
@@ -3172,8 +3173,9 @@ export default function App(): React.JSX.Element {
useEffect(() => { useEffect(() => {
if (!authSession?.accessToken) return if (!authSession?.accessToken) return
const socket: Socket = io(LMS_SOCKET_BASE_URL, { const socket: Socket = io(LMS_SOCKET_ORIGIN, {
auth: { token: authSession.accessToken }, auth: { token: authSession.accessToken },
path: LMS_SOCKET_PATH,
transports: ['websocket', 'polling'] 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_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$/, '') 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 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' export const SELECTED_COURSE_STORAGE_KEY = 'lms-selected-course-id'
@@ -45,6 +45,7 @@ type UseQaChatOptions = {
weekNumber: number weekNumber: number
apiBaseUrl: string apiBaseUrl: string
socketBaseUrl: string socketBaseUrl: string
socketPath: string
getFreshAccessToken: () => Promise<string> getFreshAccessToken: () => Promise<string>
onTitlebarNotice: (title: string, tone?: 'info' | 'warning' | 'error', addToList?: boolean) => void onTitlebarNotice: (title: string, tone?: 'info' | 'warning' | 'error', addToList?: boolean) => void
} }
@@ -64,6 +65,7 @@ export function useQaChat({
weekNumber, weekNumber,
apiBaseUrl, apiBaseUrl,
socketBaseUrl, socketBaseUrl,
socketPath,
getFreshAccessToken, getFreshAccessToken,
onTitlebarNotice onTitlebarNotice
}: UseQaChatOptions) { }: UseQaChatOptions) {
@@ -118,6 +120,7 @@ export function useQaChat({
if (!accessToken) return if (!accessToken) return
const socket: Socket = io(socketBaseUrl, { const socket: Socket = io(socketBaseUrl, {
auth: { token: accessToken }, auth: { token: accessToken },
path: socketPath,
transports: ['websocket', 'polling'] transports: ['websocket', 'polling']
}) })
@@ -135,7 +138,7 @@ export function useQaChat({
socket.off('chat.message.created', onMessageCreated) socket.off('chat.message.created', onMessageCreated)
socket.disconnect() socket.disconnect()
} }
}, [accessToken, onTitlebarNotice, socketBaseUrl]) }, [accessToken, onTitlebarNotice, socketBaseUrl, socketPath])
useEffect(() => { useEffect(() => {
if (!accessToken || !validChatWeek) { if (!accessToken || !validChatWeek) {