fix: 채팅 url 업데이트

This commit is contained in:
jhynsoo 2024-08-01 17:09:35 +09:00
parent 4e7c427fa3
commit b51a604697
4 changed files with 28 additions and 20 deletions

View File

@ -20,7 +20,7 @@ export default function useChatRoom(roomId) {
} }
chatClient.publish({ chatClient.publish({
destination: `/pub/message/${roomId}`, destination: `/pub/chat.message.${roomId}`,
body: JSON.stringify({ body: JSON.stringify({
userId: USER_ID, userId: USER_ID,
name: userName, name: userName,
@ -32,7 +32,7 @@ export default function useChatRoom(roomId) {
useEffect(() => { useEffect(() => {
client.onConnect = () => { client.onConnect = () => {
client.subscribe(`/sub/channel/${roomId}`, (response) => { client.subscribe(`/exchange/chat.exchange/*.room.${roomId}`, (response) => {
const data = JSON.parse(response.body); const data = JSON.parse(response.body);
const { content: message, name } = data; const { content: message, name } = data;

View File

@ -1,4 +1,3 @@
import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { RouterProvider } from 'react-router-dom'; import { RouterProvider } from 'react-router-dom';
@ -10,9 +9,7 @@ const queryClient = new QueryClient({
}); });
ReactDOM.createRoot(document.getElementById('root')).render( ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<RouterProvider router={router} /> <RouterProvider router={router} />
</QueryClientProvider> </QueryClientProvider>
</React.StrictMode>
); );

View File

@ -6,7 +6,6 @@ const instance = axios.create({
timeout: 1000, timeout: 1000,
headers: { headers: {
'Content-type': 'application/json;charset=utf-8', 'Content-type': 'application/json;charset=utf-8',
'Access-Control-Allow-Origin': import.meta.env.VITE_ORIGIN,
}, },
withCredentials: true, withCredentials: true,
}); });
@ -28,15 +27,24 @@ instance.interceptors.response.use(
return Promise.reject(error); return Promise.reject(error);
} }
// TODO: api url update const REFRESH_API_URL = '/user/refresh';
const REFRESH_API_URL = '/refresh-token';
return instance.post(REFRESH_API_URL).then((response) => { return instance
.post(REFRESH_API_URL)
.then((response) => {
const { accessToken } = response.data; const { accessToken } = response.data;
console.log(accessToken);
useBoundStore.setState({ token: accessToken }); useBoundStore.setState({ token: accessToken });
error.config.headers.Authorization = `${accessToken}`; error.config.headers.Authorization = `${accessToken}`;
return instance(error.config); return instance(error.config);
})
.catch((error) => {
useBoundStore.setState({ token: null });
console.log(error);
console.log('---로그아웃----');
// TODO: redirect to home
return Promise.reject(error);
}); });
} }
); );

View File

@ -1,8 +1,11 @@
import { Client } from '@stomp/stompjs'; import { Client } from '@stomp/stompjs';
import useBoundStore from '../../store';
export const chatClient = new Client({ export const chatClient = new Client({
brokerURL: import.meta.env.VITE_CHAT_URL, brokerURL: import.meta.env.VITE_CHAT_URL,
// TODO: debug 제거 debug: import.meta.env.DEV ? (str) => console.log(str) : () => {},
debug: (str) => console.log(str), reconnectDelay: 3000,
reconnectDelay: 5000, connectHeaders: {
Authorization: useBoundStore.getState().token,
},
}); });