Improve Supabase connection testing
Enhance connection testing to provide more detailed error information.
This commit is contained in:
@@ -3,10 +3,19 @@
|
||||
export const getSupabaseUrl = () => {
|
||||
// 로컬 스토리지에서 설정된 URL을 우선 사용
|
||||
const storedUrl = localStorage.getItem('supabase_url');
|
||||
if (storedUrl) return storedUrl;
|
||||
if (storedUrl) {
|
||||
// CORS 프록시 설정 확인
|
||||
const useProxy = localStorage.getItem('use_cors_proxy') === 'true';
|
||||
if (useProxy && storedUrl.startsWith('http://')) {
|
||||
// CORS 프록시 URL로 변환
|
||||
return `https://corsproxy.io/?${encodeURIComponent(storedUrl)}`;
|
||||
}
|
||||
return storedUrl;
|
||||
}
|
||||
|
||||
// 환경 변수 또는 기본값 사용
|
||||
return process.env.SUPABASE_URL || 'http://a11.ism.kr:8000';
|
||||
const defaultUrl = process.env.SUPABASE_URL || 'http://a11.ism.kr:8000';
|
||||
return defaultUrl;
|
||||
};
|
||||
|
||||
export const getSupabaseKey = () => {
|
||||
@@ -18,12 +27,29 @@ export const getSupabaseKey = () => {
|
||||
return process.env.SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlIiwiaWF0IjoxNzQyMDM5MzU4LCJleHAiOjQ4OTU2MzkzNTh9.XK0vetdwv_H2MHj4ewTfZGtSbrbSNDaV5xJhNo_Hdp8';
|
||||
};
|
||||
|
||||
// CORS 프록시 사용 여부 설정
|
||||
export const useCorsProxy = (enabled: boolean) => {
|
||||
localStorage.setItem('use_cors_proxy', enabled.toString());
|
||||
};
|
||||
|
||||
// CORS 프록시 사용 여부 확인
|
||||
export const isCorsProxyEnabled = () => {
|
||||
return localStorage.getItem('use_cors_proxy') === 'true';
|
||||
};
|
||||
|
||||
// 온프레미스 연결을 위한 설정 도우미 함수
|
||||
export const configureSupabase = (url: string, key: string) => {
|
||||
export const configureSupabase = (url: string, key: string, useProxy: boolean = false) => {
|
||||
// 로컬 스토리지에 설정 저장
|
||||
localStorage.setItem('supabase_url', url);
|
||||
localStorage.setItem('supabase_key', key);
|
||||
localStorage.setItem('use_cors_proxy', useProxy.toString());
|
||||
|
||||
// 페이지 새로고침 - 새로운 설정으로 Supabase 클라이언트 초기화
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
// 원본 URL 반환 (프록시 없는 URL)
|
||||
export const getOriginalSupabaseUrl = () => {
|
||||
const storedUrl = localStorage.getItem('supabase_url');
|
||||
return storedUrl || process.env.SUPABASE_URL || 'http://a11.ism.kr:8000';
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
import { supabase } from './client';
|
||||
import { getSupabaseUrl, getSupabaseKey, getOriginalSupabaseUrl, isCorsProxyEnabled } from './config';
|
||||
|
||||
// 테스트용 직접 로그인 함수 (디버깅 전용)
|
||||
export const testSupabaseLogin = async (email: string, password: string) => {
|
||||
@@ -27,7 +28,9 @@ export const testSupabaseLogin = async (email: string, password: string) => {
|
||||
// API 테스트 도우미 함수
|
||||
export const testSupabaseConnection = async () => {
|
||||
const results = {
|
||||
url: getSupabaseUrl(),
|
||||
url: getOriginalSupabaseUrl(), // 원본 URL
|
||||
proxyUrl: getSupabaseUrl(), // 프록시 적용된 URL
|
||||
usingProxy: isCorsProxyEnabled(), // 프록시 사용 여부
|
||||
client: !!supabase,
|
||||
restApi: false,
|
||||
auth: false,
|
||||
@@ -39,7 +42,10 @@ export const testSupabaseConnection = async () => {
|
||||
// 1. REST API 접근 테스트
|
||||
try {
|
||||
console.log('REST API 테스트 시작...');
|
||||
const response = await fetch(`${results.url}/rest/v1/`, {
|
||||
const apiUrl = `${results.proxyUrl}/rest/v1/`;
|
||||
console.log('REST API 테스트 URL:', apiUrl);
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -108,12 +114,3 @@ export const testSupabaseConnection = async () => {
|
||||
console.log('Supabase 연결 테스트 결과:', results);
|
||||
return results;
|
||||
};
|
||||
|
||||
// 필요한 함수 불러오기
|
||||
function getSupabaseUrl() {
|
||||
return localStorage.getItem('supabase_url') || process.env.SUPABASE_URL || 'http://a11.ism.kr:8000';
|
||||
}
|
||||
|
||||
function getSupabaseKey() {
|
||||
return localStorage.getItem('supabase_key') || process.env.SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlIiwiaWF0IjoxNzQyMDM5MzU4LCJleHAiOjQ4OTU2MzkzNTh9.XK0vetdwv_H2MHj4ewTfZGtSbrbSNDaV5xJhNo_Hdp8';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user