Improve Supabase connection testing

Enhance the Supabase connection test to provide more detailed error information and handle potential CORS issues.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 12:32:40 +00:00
parent a55e780eec
commit 785e69a42c
4 changed files with 189 additions and 36 deletions

View File

@@ -6,15 +6,36 @@ export const getSupabaseUrl = () => {
if (storedUrl) {
// CORS 프록시 설정 확인
const useProxy = localStorage.getItem('use_cors_proxy') === 'true';
const proxyType = localStorage.getItem('proxy_type') || 'corsproxy.io';
if (useProxy) {
// CORS 프록시 URL로 변환 (URL 구조 개선)
const cleanUrl = storedUrl.trim();
// URL에 이미 프로토콜이 포함되어 있는지 확인
const cleanUrl = storedUrl.trim();
const hasProtocol = cleanUrl.startsWith('http://') || cleanUrl.startsWith('https://');
const urlForProxy = hasProtocol ? cleanUrl : `http://${cleanUrl}`;
// 프록시 URL 생성 시 더 정확한 인코딩
const proxyUrl = `https://corsproxy.io/?${encodeURIComponent(urlForProxy)}`;
// 선택된 프록시 타입에 따라 URL 생성
let proxyUrl = '';
switch (proxyType) {
case 'corsproxy.io':
// 주의: 쿼리 파라미터가 포함된 URL에서 발생하는 문제를 해결하기 위해
// 전체 URL을 인코딩하고 끝에 슬래시 추가
proxyUrl = `https://corsproxy.io/?${encodeURIComponent(urlForProxy)}`;
break;
case 'thingproxy':
proxyUrl = `https://thingproxy.freeboard.io/fetch/${urlForProxy}`;
break;
case 'allorigins':
proxyUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(urlForProxy)}`;
break;
case 'cors-anywhere':
proxyUrl = `https://cors-anywhere.herokuapp.com/${urlForProxy}`;
break;
default:
proxyUrl = `https://corsproxy.io/?${encodeURIComponent(urlForProxy)}`;
}
console.log('CORS 프록시 URL 생성:', proxyUrl);
return proxyUrl;
}
@@ -40,13 +61,23 @@ export const useCorsProxy = (enabled: boolean) => {
localStorage.setItem('use_cors_proxy', enabled.toString());
};
// CORS 프록시 유형 설정
export const setProxyType = (proxyType: string) => {
localStorage.setItem('proxy_type', proxyType);
};
// 현재 사용 중인 프록시 유형 가져오기
export const getProxyType = () => {
return localStorage.getItem('proxy_type') || 'corsproxy.io';
};
// CORS 프록시 사용 여부 확인
export const isCorsProxyEnabled = () => {
return localStorage.getItem('use_cors_proxy') === 'true';
};
// 온프레미스 연결을 위한 설정 도우미 함수
export const configureSupabase = (url: string, key: string, useProxy: boolean = false) => {
export const configureSupabase = (url: string, key: string, useProxy: boolean = false, proxyType: string = 'corsproxy.io') => {
// URL 정리 (앞뒤 공백 제거)
const cleanUrl = url.trim();
@@ -59,6 +90,7 @@ export const configureSupabase = (url: string, key: string, useProxy: boolean =
localStorage.setItem('supabase_url', normalizedUrl);
localStorage.setItem('supabase_key', key);
localStorage.setItem('use_cors_proxy', useProxy.toString());
localStorage.setItem('proxy_type', proxyType);
// 페이지 새로고침 - 새로운 설정으로 Supabase 클라이언트 초기화
window.location.reload();