Files
web-temp/layers/composables/useGetGameDomain.ts
2025-09-19 14:43:21 +09:00

36 lines
906 B
TypeScript

import { getHeader, getRequestHost } from 'h3'
import { useRequestEvent } from 'nuxt/app'
/**
* 게임 도메인을 가져오는 컴포저블 함수
* 서버와 클라이언트 환경에서 모두 동작
* @returns 게임 도메인 문자열
*/
export const useGetGameDomain = (): string => {
try {
if (import.meta.client) {
const host = window.location.host || ''
return host.split(':')[0]
}
const event = useRequestEvent()
if (!event) {
return ''
}
// 미들웨어에서 설정한 gameDomain가 있다면 우선 사용
if (event.context.gameDomain) {
return event.context.gameDomain
}
const host =
(getHeader(event, 'host') || getRequestHost(event)).toString() || ''
const cleanHost = host.split(':')[0]
return cleanHost || ''
} catch (error) {
console.error('useGetGameDomain error:', error)
return ''
}
}