Configure Supabase Cloud connection

Configures the application to connect to a Supabase Cloud instance.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 16:04:45 +00:00
parent e40442f9cf
commit 68a4d93426
3 changed files with 23 additions and 155 deletions

View File

@@ -1,3 +1,4 @@
// This file is automatically generated. Do not edit it directly.
import { createClient } from '@supabase/supabase-js';
import type { Database } from './types';
@@ -8,4 +9,4 @@ const SUPABASE_PUBLISHABLE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiO
// Import the supabase client like this:
// import { supabase } from "@/integrations/supabase/client";
export const supabase = createClient<Database>(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY);
export const supabase = createClient<Database>(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY);

View File

@@ -1,42 +1,24 @@
import { createClient } from '@supabase/supabase-js';
import { getSupabaseUrl, getSupabaseKey } from './config';
import { customFetch } from './customFetch';
const supabaseUrl = getSupabaseUrl();
const supabaseAnonKey = getSupabaseKey();
// 유효한 URL이 설정되었는지 확인
const isValidUrl = supabaseUrl && supabaseAnonKey &&
!supabaseUrl.includes('your-onpremise-supabase-url') &&
!supabaseAnonKey.includes('your-onpremise-anon-key');
let supabaseClient;
try {
console.log(`Supabase 클라이언트 생성 시도: ${supabaseUrl}`);
console.log(`Supabase 클라이언트 생성 : ${supabaseUrl}`);
// Supabase 클라이언트 생성
supabaseClient = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
autoRefreshToken: true,
persistSession: true,
// 온프레미스 설치를 위한 추가 설정
flowType: 'implicit',
},
global: {
// 커스텀 fetch 구현
fetch: customFetch
}
});
// Supabase 연결 로그
console.log('Supabase 클라이언트가 생성되었습니다.');
// 유효성 검사 로그
if (!isValidUrl) {
console.warn('경고: 기본 Supabase URL 또는 Anon Key가 감지되었습니다. Supabase 설정 페이지에서 온프레미스 설정을 구성하세요.');
}
console.log('Supabase Cloud 클라이언트가 생성되었습니다.');
// 연결 테스트 - 별도 파일로 이동됨
import('./connectionTest').then(module => {
@@ -67,4 +49,4 @@ try {
}
export const supabase = supabaseClient;
export { isValidUrl };
export const isValidUrl = true; // Supabase Cloud 환경에서는 항상 true

View File

@@ -1,162 +1,47 @@
// 온프레미스 Supabase URL과 anon key 설정
// Supabase Cloud URL과 anon key 설정 (고정값 사용)
export const getSupabaseUrl = () => {
// 로컬 스토리지에서 설정된 URL을 우선 사용
const storedUrl = localStorage.getItem('supabase_url');
if (storedUrl) {
// CORS 프록시 설정 확인
const useProxy = localStorage.getItem('use_cors_proxy') === 'true';
const proxyType = localStorage.getItem('proxy_type') || 'cloudflare';
// HTTP URL 사용 시 자동으로 프록시 활성화
const isHttpUrl = storedUrl.startsWith('http:') && !storedUrl.startsWith('http://localhost');
if (isHttpUrl && !useProxy) {
// 자동으로 프록시 설정 (Cloudflare)
localStorage.setItem('use_cors_proxy', 'true');
localStorage.setItem('proxy_type', 'cloudflare');
console.log('HTTP URL 감지: CORS 프록시 자동 활성화 (Cloudflare)');
}
// 프록시 사용 여부 재확인 (자동 활성화 후)
const shouldUseProxy = localStorage.getItem('use_cors_proxy') === 'true';
const currentProxyType = localStorage.getItem('proxy_type') || 'cloudflare';
if (shouldUseProxy) {
// URL에 이미 프로토콜이 포함되어 있는지 확인
const cleanUrl = storedUrl.trim();
const hasProtocol = cleanUrl.startsWith('http://') || cleanUrl.startsWith('https://');
const urlForProxy = hasProtocol ? cleanUrl : `http://${cleanUrl}`;
// 선택된 프록시 타입에 따라 URL 생성
let proxyUrl = '';
switch (currentProxyType) {
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;
case 'cloudflare':
// Cloudflare Workers CORS 프록시
proxyUrl = `https://cors-proxy.azurewebsites.net/api/cors-proxy?url=${encodeURIComponent(urlForProxy)}`;
break;
case 'local-proxy':
// 사용자 지정 로컬 프록시 (개발 환경용)
proxyUrl = `http://localhost:8080/proxy?url=${encodeURIComponent(urlForProxy)}`;
break;
default:
proxyUrl = `https://cors-proxy.azurewebsites.net/api/cors-proxy?url=${encodeURIComponent(urlForProxy)}`;
}
console.log('CORS 프록시 URL 생성:', proxyUrl);
return proxyUrl;
}
return storedUrl;
}
// 기본값 사용 (환경 변수 대신)
return 'https://a11.ism.kr';
// Supabase Cloud URL 사용
return "https://qnerebtvwwfobfzdoftx.supabase.co";
};
// 원본 URL 반환 (프록시 없는 URL)
// 원본 URL 반환
export const getOriginalSupabaseUrl = () => {
const storedUrl = localStorage.getItem('supabase_url');
return storedUrl || 'https://a11.ism.kr';
return "https://qnerebtvwwfobfzdoftx.supabase.co";
};
export const getSupabaseKey = () => {
// 로컬 스토리지에서 설정된 키를 우선 사용
const storedKey = localStorage.getItem('supabase_key');
if (storedKey) return storedKey;
// 기본값 사용 (환경 변수 대신)
return 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlIiwiaWF0IjoxNzQyMDQ4NTEwLCJleHAiOjQ4OTU2NDg1MTB9.BZx5MF-HldDju9r4eFwOVp9_qj6GOdkjaG6VrJAYAIg';
// Supabase Cloud anon key 사용
return "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InFuZXJlYnR2d3dmb2JmemRvZnR4Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDIwNTE0MzgsImV4cCI6MjA1NzYyNzQzOH0.Wm7h2DUhoQbeANuEM3wm2tz22ITrVEW8FizyLgIVmv8";
};
// Supabase 키 유효성 검사
export const isValidSupabaseKey = () => {
const key = getSupabaseKey();
return key && !key.includes('your-onpremise-anon-key');
return true; // Supabase Cloud에서는 항상 유효함
};
// CORS 프록시 사용 여부 설정
// CORS 프록시 관련 함수들 (Supabase Cloud에서는 필요 없음)
export const useCorsProxy = (enabled: boolean) => {
localStorage.setItem('use_cors_proxy', enabled.toString());
// HTTP URL 사용 시 프록시 비활성화 방지
if (!enabled) {
const storedUrl = localStorage.getItem('supabase_url');
const isHttpUrl = storedUrl && storedUrl.startsWith('http:') && !storedUrl.startsWith('http://localhost');
if (isHttpUrl) {
// HTTP URL에서는 프록시를 강제로 유지
localStorage.setItem('use_cors_proxy', 'true');
console.warn('경고: HTTP URL 사용 시 CORS 프록시를 비활성화할 수 없습니다. 프록시가 자동으로 유지됩니다.');
return true;
}
}
return enabled;
return false; // Supabase Cloud에서는 항상 비활성화
};
// CORS 프록시 유형 설정
export const setProxyType = (proxyType: string) => {
localStorage.setItem('proxy_type', proxyType);
// Supabase Cloud에서는 아무 작업도 하지 않음
};
// 현재 사용 중인 프록시 유형 가져오기
export const getProxyType = () => {
return localStorage.getItem('proxy_type') || 'cloudflare';
return 'none'; // Supabase Cloud에서는 프록시 사용 안함
};
// CORS 프록시 사용 여부 확인
export const isCorsProxyEnabled = () => {
// HTTP URL 사용 시 자동으로 프록시 활성화
const storedUrl = localStorage.getItem('supabase_url');
const isHttpUrl = storedUrl && storedUrl.startsWith('http:') && !storedUrl.startsWith('http://localhost');
if (isHttpUrl) {
// HTTP URL에서는 프록시 자동 활성화
localStorage.setItem('use_cors_proxy', 'true');
return true;
}
return localStorage.getItem('use_cors_proxy') === 'true';
return false; // Supabase Cloud에서는 항상 false
};
// 온프레미스 연결을 위한 설정 도우미 함수
export const configureSupabase = (url: string, key: string, useProxy: boolean = true, proxyType: string = 'cloudflare') => {
// URL 정리 (앞뒤 공백 제거)
const cleanUrl = url.trim();
// 구성 도우미 함수 - Cloud 환경에서는 단순화
export const configureSupabase = (url: string, key: string, useProxy: boolean = false, proxyType: string = 'none') => {
console.log('Supabase Cloud를 사용 중이므로 설정이 무시됩니다');
// 실제 설정은 변경되지 않음 (Cloud URL 및 키는 고정)
// URL에 프로토콜이 없는 경우 http:// 추가
const normalizedUrl = (cleanUrl.startsWith('http://') || cleanUrl.startsWith('https://'))
? cleanUrl
: `http://${cleanUrl}`;
// HTTP URL을 사용하고 프록시가 활성화되지 않은 경우 자동 활성화
const isHttpUrl = normalizedUrl.startsWith('http:') && !normalizedUrl.startsWith('http://localhost');
if (isHttpUrl && !useProxy) {
console.warn('경고: HTTP URL 감지, CORS 프록시 자동 활성화');
useProxy = true;
proxyType = 'cloudflare';
}
// 로컬 스토리지에 설정 저장
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();
};