Files
web-temp/layers/middleware/init.route.global.ts
“hyeonggkim” 87b1ca0db1 feat: CtLayout01 커스텀 콘텐츠 기능 개선
- fnCustomVideo 유튜브 팝업 함수 추가
- script/link exclude 속성 지원
- 전역 함수 등록 로직 통합 (registerGlobalFunctions)
- CSS Selector injection 보안 취약점 수정
- 사용되지 않는 변수/props 제거
- DOMPurify exclude, defer 속성 허용

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 19:21:19 +09:00

51 lines
1.5 KiB
TypeScript

import { DEFAULT_LOCALE_CODE, ISO_LANGUAGE_CODES } from '@/i18n.config'
import { csrGetFinalLocale } from '#layers/utils/localeUtil'
import { parseUrl, isExternalUrl } from '#layers/utils/urlUtil'
export default defineNuxtRouteMiddleware(to => {
// 서버에서는 실행하지 않음 (서버 미들웨어에서 이미 처리)
if (import.meta.server) return
// error 페이지와 inspection 페이지는 미들웨어 실행 제외
if (to.path.includes('/error') || to.path.includes('/inspection')) {
return
}
const gameDataStore = useGameDataStore()
const { langCodes, defaultLangCode, intro } = storeToRefs(gameDataStore)
// 게임 데이터 스토어가 초기화되지 않았으면 대기
if (!langCodes.value || !defaultLangCode.value || !intro.value) {
return
}
const fullPath = to.fullPath || to.path || ''
// 최종 로케일 결정
const finalLocale =
csrGetFinalLocale(fullPath, langCodes.value) ||
defaultLangCode.value ||
DEFAULT_LOCALE_CODE
// parseUrl을 사용하여 최종 경로 계산
const introPageUrl = intro.value?.page_url || ''
const finalPath = parseUrl(
fullPath,
finalLocale,
langCodes.value,
ISO_LANGUAGE_CODES,
introPageUrl
)
// 현재 경로와 최종 경로가 같으면 리다이렉트 불필요
if (fullPath.split('?')[0] === finalPath.split('?')[0]) {
return
}
// 외부 URL인지 확인
const isExternal = isExternalUrl(finalPath)
// 리다이렉트 수행
return navigateTo(finalPath, { external: isExternal })
})