feat. GR_VISUAL_03 컴포넌트 제작
This commit is contained in:
35
layers/composables/useGetGameDomain.ts
Normal file
35
layers/composables/useGetGameDomain.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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 ''
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user