diff --git a/src/utils/auth/network/corsUtils.ts b/src/utils/auth/network/corsUtils.ts deleted file mode 100644 index 3c7c02d..0000000 --- a/src/utils/auth/network/corsUtils.ts +++ /dev/null @@ -1,45 +0,0 @@ - -import { isCorsProxyEnabled, getProxyType, getSupabaseUrl, getOriginalSupabaseUrl } from '@/lib/supabase/config'; - -/** - * CORS 문제 확인 - */ -export const hasCorsIssue = (error: any): boolean => { - if (!error) return false; - - const errorMessage = error.message || ''; - return ( - errorMessage.includes('Failed to fetch') || - errorMessage.includes('CORS') || - errorMessage.includes('Network') || - errorMessage.includes('프록시') - ); -}; - -/** - * HTTP URL이 프록시 없이 사용되고 있는지 확인하고 처리 - */ -export const handleHttpUrlWithoutProxy = (): boolean => { - // HTTP URL을 사용하는데 프록시가 비활성화된 경우 - const originalUrl = getOriginalSupabaseUrl(); - const usingProxy = isCorsProxyEnabled(); - - if (originalUrl.startsWith('http:') && !usingProxy) { - // 자동으로 프록시 활성화 - localStorage.setItem('use_cors_proxy', 'true'); - localStorage.setItem('proxy_type', 'cloudflare'); - return true; - } - return false; -}; - -/** - * 프록시 정보 로깅 - */ -export const logProxyInfo = (): void => { - const usingProxy = isCorsProxyEnabled(); - const proxyType = getProxyType(); - const supabaseUrl = getSupabaseUrl(); - - console.log(`연결 테스트 - CORS 프록시: ${usingProxy ? '사용 중' : '미사용'}, 타입: ${proxyType}, URL: ${supabaseUrl}`); -}; diff --git a/src/utils/auth/network/enhancedConnectionCheck.ts b/src/utils/auth/network/enhancedConnectionCheck.ts deleted file mode 100644 index a24fbbf..0000000 --- a/src/utils/auth/network/enhancedConnectionCheck.ts +++ /dev/null @@ -1,80 +0,0 @@ - -import { getSupabaseUrl, isCorsProxyEnabled, getProxyType, getOriginalSupabaseUrl } from '@/lib/supabase/config'; -import { logProxyInfo, handleHttpUrlWithoutProxy } from './corsUtils'; - -/** - * 강화된 서버 연결 검사: 다양한 경로로 시도 - */ -export const verifySupabaseConnection = async (): Promise<{ - connected: boolean; - message: string; - statusCode?: number; - details?: string; -}> => { - const supabaseUrl = getSupabaseUrl(); - if (!supabaseUrl) { - return { - connected: false, - message: 'Supabase URL이 설정되지 않았습니다' - }; - } - - // 프록시 정보 로깅 - const usingProxy = isCorsProxyEnabled(); - const proxyType = getProxyType(); - console.log(`강화된 연결 테스트 - 프록시: ${usingProxy ? '사용 중' : '미사용'}, 타입: ${proxyType}, URL: ${supabaseUrl}`); - - // 무작위 쿼리 파라미터를 추가하여 캐시 방지 - const cacheParam = `?_nocache=${Date.now()}`; - - // 다양한 경로를 순차적으로 시도 - const paths = [ - '/auth/v1/', - '/', - '/rest/v1/', - '/storage/v1/' - ]; - - for (const path of paths) { - try { - console.log(`경로 시도: ${path}`); - const response = await fetch(`${supabaseUrl}${path}${cacheParam}`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - 'apikey': localStorage.getItem('supabase_key') || '' - }, - signal: AbortSignal.timeout(15000) // 타임아웃 시간 증가 - }); - - console.log(`경로 ${path} 응답 상태:`, response.status); - - // 어떤 응답이든 서버가 살아있다는 신호로 간주 - return { - connected: true, - message: `서버 연결 성공 (${path})`, - statusCode: response.status, - details: `${response.status} ${response.statusText}` - }; - } catch (error) { - console.warn(`${path} 경로 연결 실패:`, error); - // 계속 다음 경로 시도 - } - } - - // HTTP URL을 사용하는데 프록시가 비활성화된 경우 처리 - if (handleHttpUrlWithoutProxy()) { - return { - connected: false, - message: 'HTTP URL에 직접 접근할 수 없어 CORS 프록시를 자동으로 활성화했습니다. 페이지를 새로고침하고 다시 시도하세요.', - details: 'CORS 제한으로 인해 HTTP URL에 직접 접근할 수 없습니다' - }; - } - - // 모든 경로 시도 실패 - return { - connected: false, - message: '모든 Supabase 경로에 대한 연결 시도 실패', - details: '네트워크 연결 또는 서버 주소를 확인하세요' - }; -}; diff --git a/src/utils/auth/network/index.ts b/src/utils/auth/network/index.ts index 3f33c5b..0388d73 100644 --- a/src/utils/auth/network/index.ts +++ b/src/utils/auth/network/index.ts @@ -1,5 +1,9 @@ // 네트워크 유틸리티 모듈 -export { hasCorsIssue, handleHttpUrlWithoutProxy, logProxyInfo } from './corsUtils'; -export { verifyServerConnection } from './basicConnectionCheck'; -export { verifySupabaseConnection } from './enhancedConnectionCheck'; +export { + hasCorsIssue, + handleHttpUrlWithoutProxy, + logProxyInfo, + verifyServerConnection, + verifySupabaseConnection +} from './networkUtils'; diff --git a/src/utils/auth/network/basicConnectionCheck.ts b/src/utils/auth/network/networkUtils.ts similarity index 57% rename from src/utils/auth/network/basicConnectionCheck.ts rename to src/utils/auth/network/networkUtils.ts index a34dd34..1da2ed3 100644 --- a/src/utils/auth/network/basicConnectionCheck.ts +++ b/src/utils/auth/network/networkUtils.ts @@ -1,6 +1,48 @@ import { getSupabaseUrl, isCorsProxyEnabled, getProxyType, getOriginalSupabaseUrl } from '@/lib/supabase/config'; -import { logProxyInfo, handleHttpUrlWithoutProxy } from './corsUtils'; + +/** + * CORS 문제 확인 + */ +export const hasCorsIssue = (error: any): boolean => { + if (!error) return false; + + const errorMessage = error.message || ''; + return ( + errorMessage.includes('Failed to fetch') || + errorMessage.includes('CORS') || + errorMessage.includes('Network') || + errorMessage.includes('프록시') + ); +}; + +/** + * HTTP URL이 프록시 없이 사용되고 있는지 확인하고 처리 + */ +export const handleHttpUrlWithoutProxy = (): boolean => { + // HTTP URL을 사용하는데 프록시가 비활성화된 경우 + const originalUrl = getOriginalSupabaseUrl(); + const usingProxy = isCorsProxyEnabled(); + + if (originalUrl.startsWith('http:') && !usingProxy) { + // 자동으로 프록시 활성화 + localStorage.setItem('use_cors_proxy', 'true'); + localStorage.setItem('proxy_type', 'cloudflare'); + return true; + } + return false; +}; + +/** + * 프록시 정보 로깅 + */ +export const logProxyInfo = (): void => { + const usingProxy = isCorsProxyEnabled(); + const proxyType = getProxyType(); + const supabaseUrl = getSupabaseUrl(); + + console.log(`연결 테스트 - CORS 프록시: ${usingProxy ? '사용 중' : '미사용'}, 타입: ${proxyType}, URL: ${supabaseUrl}`); +}; /** * 서버 연결 상태 검사 @@ -136,3 +178,80 @@ export const verifyServerConnection = async (): Promise<{ }; } }; + +/** + * 강화된 서버 연결 검사: 다양한 경로로 시도 + */ +export const verifySupabaseConnection = async (): Promise<{ + connected: boolean; + message: string; + statusCode?: number; + details?: string; +}> => { + const supabaseUrl = getSupabaseUrl(); + if (!supabaseUrl) { + return { + connected: false, + message: 'Supabase URL이 설정되지 않았습니다' + }; + } + + // 프록시 정보 로깅 + const usingProxy = isCorsProxyEnabled(); + const proxyType = getProxyType(); + console.log(`강화된 연결 테스트 - 프록시: ${usingProxy ? '사용 중' : '미사용'}, 타입: ${proxyType}, URL: ${supabaseUrl}`); + + // 무작위 쿼리 파라미터를 추가하여 캐시 방지 + const cacheParam = `?_nocache=${Date.now()}`; + + // 다양한 경로를 순차적으로 시도 + const paths = [ + '/auth/v1/', + '/', + '/rest/v1/', + '/storage/v1/' + ]; + + for (const path of paths) { + try { + console.log(`경로 시도: ${path}`); + const response = await fetch(`${supabaseUrl}${path}${cacheParam}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'apikey': localStorage.getItem('supabase_key') || '' + }, + signal: AbortSignal.timeout(15000) // 타임아웃 시간 증가 + }); + + console.log(`경로 ${path} 응답 상태:`, response.status); + + // 어떤 응답이든 서버가 살아있다는 신호로 간주 + return { + connected: true, + message: `서버 연결 성공 (${path})`, + statusCode: response.status, + details: `${response.status} ${response.statusText}` + }; + } catch (error) { + console.warn(`${path} 경로 연결 실패:`, error); + // 계속 다음 경로 시도 + } + } + + // HTTP URL을 사용하는데 프록시가 비활성화된 경우 처리 + if (handleHttpUrlWithoutProxy()) { + return { + connected: false, + message: 'HTTP URL에 직접 접근할 수 없어 CORS 프록시를 자동으로 활성화했습니다. 페이지를 새로고침하고 다시 시도하세요.', + details: 'CORS 제한으로 인해 HTTP URL에 직접 접근할 수 없습니다' + }; + } + + // 모든 경로 시도 실패 + return { + connected: false, + message: '모든 Supabase 경로에 대한 연결 시도 실패', + details: '네트워크 연결 또는 서버 주소를 확인하세요' + }; +}; diff --git a/src/utils/auth/networkUtils.ts b/src/utils/auth/networkUtils.ts index ab5c965..0e87f03 100644 --- a/src/utils/auth/networkUtils.ts +++ b/src/utils/auth/networkUtils.ts @@ -4,5 +4,7 @@ export { hasCorsIssue, verifyServerConnection, - verifySupabaseConnection -} from './network'; + verifySupabaseConnection, + handleHttpUrlWithoutProxy, + logProxyInfo +} from './network/networkUtils';