File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed
Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 11import { WebSocketMessage } from '../websocket/constants/constants' ;
2- import { api } from './api' ;
32
43export type RecoveryMessage = {
54 streamId : string ;
@@ -14,15 +13,34 @@ type RecoveryResponse = {
1413 errorMessage ?: string ;
1514} ;
1615
16+ const getApiUrl = ( ) : string => {
17+ // Storybook 환경에서는 process.env가 없을 수 있음
18+ if ( typeof process !== 'undefined' && process . env ?. API_URL ) {
19+ return process . env . API_URL ;
20+ }
21+ return '' ;
22+ } ;
23+
1724export const fetchRecoveryMessages = async (
1825 joinCode : string ,
1926 playerName : string ,
2027 lastStreamId : string
2128) : Promise < RecoveryMessage [ ] > => {
2229 try {
23- const response = await api . post < RecoveryResponse , undefined > (
24- `/api/rooms/${ joinCode } /recovery?playerName=${ encodeURIComponent ( playerName ) } &lastId=${ encodeURIComponent ( lastStreamId ) } `
25- ) ;
30+ const apiUrl = getApiUrl ( ) ;
31+ const url = `${ apiUrl } /api/rooms/${ joinCode } /recovery?playerName=${ encodeURIComponent ( playerName ) } &lastId=${ encodeURIComponent ( lastStreamId ) } ` ;
32+
33+ const res = await fetch ( url , {
34+ method : 'POST' ,
35+ headers : { 'Content-Type' : 'application/json' } ,
36+ } ) ;
37+
38+ if ( ! res . ok ) {
39+ console . warn ( 'Recovery API 실패:' , res . status ) ;
40+ return [ ] ;
41+ }
42+
43+ const response : RecoveryResponse = await res . json ( ) ;
2644
2745 if ( ! response . success ) {
2846 console . warn ( 'Recovery API 실패:' , response . errorMessage ) ;
You can’t perform that action at this time.
0 commit comments