fix(chat): use Engine.IO path /chat for admin oversight socket
Match consumer/backend so oversight realtime uses wss://host/chat instead of the default /socket.io path.
This commit is contained in:
parent
3517a1c86c
commit
c2bc256103
@ -11,4 +11,7 @@ const resolveChatSocketUrl = (raw?: string): string => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const CHAT_SOCKET_URL = resolveChatSocketUrl(process.env.NEXT_PUBLIC_API_URL)
|
export const CHAT_SOCKET_URL = resolveChatSocketUrl(process.env.NEXT_PUBLIC_API_URL)
|
||||||
|
/** Socket.IO namespace (logical channel). */
|
||||||
export const CHAT_SOCKET_NAMESPACE = '/chat'
|
export const CHAT_SOCKET_NAMESPACE = '/chat'
|
||||||
|
/** Engine.IO transport path — appears as `wss://host/chat/...` (not `/socket.io`). */
|
||||||
|
export const CHAT_SOCKET_PATH = '/chat'
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { io } from 'socket.io-client'
|
import { io } from 'socket.io-client'
|
||||||
|
|
||||||
import { CHAT_SOCKET_NAMESPACE, CHAT_SOCKET_URL } from '@/config/chatSocket'
|
import { CHAT_SOCKET_NAMESPACE, CHAT_SOCKET_PATH, CHAT_SOCKET_URL } from '@/config/chatSocket'
|
||||||
import useAuth from '@/hooks/useAuth'
|
import useAuth from '@/hooks/useAuth'
|
||||||
import { reportBrowserEvent } from '@/lib/observability/client'
|
import { reportBrowserEvent } from '@/lib/observability/client'
|
||||||
import type { AdminChatMessage } from '@/services/adminChat'
|
import type { AdminChatMessage } from '@/services/adminChat'
|
||||||
@ -34,6 +34,7 @@ const useAdminChatSocket = (conversationId: string, onMessage: (message: AdminCh
|
|||||||
let disconnectTimer: ReturnType<typeof setTimeout> | undefined
|
let disconnectTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
let retryTimer: ReturnType<typeof setTimeout> | undefined
|
let retryTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
const socket = io(`${CHAT_SOCKET_URL}${CHAT_SOCKET_NAMESPACE}`, {
|
const socket = io(`${CHAT_SOCKET_URL}${CHAT_SOCKET_NAMESPACE}`, {
|
||||||
|
path: CHAT_SOCKET_PATH,
|
||||||
transports: ['websocket'],
|
transports: ['websocket'],
|
||||||
autoConnect: true,
|
autoConnect: true,
|
||||||
auth: { token: user.accessToken },
|
auth: { token: user.accessToken },
|
||||||
|
|||||||
@ -140,8 +140,12 @@ const nextConfig = {
|
|||||||
destination: `${apiProxyTarget}/api/v1/:path*`,
|
destination: `${apiProxyTarget}/api/v1/:path*`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
source: '/socket.io/:path*',
|
source: '/chat',
|
||||||
destination: `${apiProxyTarget}/socket.io/:path*`,
|
destination: `${apiProxyTarget}/chat`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/chat/:path*',
|
||||||
|
destination: `${apiProxyTarget}/chat/:path*`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
4
proxy.ts
4
proxy.ts
@ -83,7 +83,7 @@ export default function proxy(request: NextRequest) {
|
|||||||
|
|
||||||
const { pathname, searchParams } = request.nextUrl
|
const { pathname, searchParams } = request.nextUrl
|
||||||
|
|
||||||
if (pathname === '/api' || pathname.startsWith('/api/') || pathname === '/socket.io' || pathname.startsWith('/socket.io/')) {
|
if (pathname === '/api' || pathname.startsWith('/api/') || pathname === '/chat' || pathname.startsWith('/chat/')) {
|
||||||
if (!shouldStripForwardedBrowserOrigin()) {
|
if (!shouldStripForwardedBrowserOrigin()) {
|
||||||
return NextResponse.next()
|
return NextResponse.next()
|
||||||
}
|
}
|
||||||
@ -163,5 +163,5 @@ export default function proxy(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: ['/api/:path*', '/socket.io/:path*', '/((?!_next|_vercel|.*\\..*).*)'],
|
matcher: ['/api/:path*', '/chat', '/chat/:path*', '/((?!_next|_vercel|.*\\..*).*)'],
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user