(() => { // 운영 도메인에서는 sso.gongbiz.kr, 그 외(개발 샵바이·로컬)에서는 dev-sso.gongbiz.kr 사용 const PROD_HOSTS = [ 'gongbizstore.com', 'www.gongbizstore.com', 'm.gongbizstore.com', 'gongstore.shopby.co.kr', // 구 운영 기본 도메인 (gongbizstore.com 으로 리다이렉트됨) ]; const isProd = PROD_HOSTS.includes(location.hostname); const baseUrl = isProd ? 'https://sso.gongbiz.kr' : 'https://dev-sso.gongbiz.kr'; // CRM(b2b 백엔드) 베이스 URL. 스토어 소비자 가입/탈퇴 등 REST 호출에 사용 const apiBaseUrl = isProd ? 'https://gongbiz.kr' : 'https://crm-dev1.gongbiz.kr'; // Keycloak realm 및 스토어 로그인용 client (소셜 간편로그인 kc_idp_hint, 토큰 교환에 사용) const realm = 'gongbiz'; const keycloakClientId = 'cafe24'; window.GongbizSsoEnv = { isProd, baseUrl, apiBaseUrl, realm, keycloakClientId, /** openid-connect 엔드포인트 URL. 예: endpoint('token'), endpoint('auth') */ endpoint(name) { return `${baseUrl}/realms/${realm}/protocol/openid-connect/${name}`; }, /** * sso 인가 링크(a 태그)의 호스트를 환경에 맞게 교체하고 * redirect_uri 를 현재 origin 기준으로 맞춘다. */ rewriteAuthLink(el, redirectPath = '/callback/gongbiz-auth-code-callback.html') { if (!el) return; const url = new URL(el.href); const base = new URL(baseUrl); url.protocol = base.protocol; url.host = base.host; url.searchParams.set('redirect_uri', `${location.origin}${redirectPath}`); el.href = url.toString(); }, /** 문서 내 모든 openid-connect /auth 링크에 rewriteAuthLink 적용 */ rewriteAllAuthLinks(redirectPath) { document .querySelectorAll('a[href*="/realms/gongbiz/protocol/openid-connect/auth"]') .forEach((el) => this.rewriteAuthLink(el, redirectPath)); }, }; })();