Files
web-temp/layers/middleware/init.route.global.ts
2025-10-17 17:51:19 +09:00

34 lines
1017 B
TypeScript

import { useGameDataStore } from '#layers/stores/useGameDataStore'
export default defineNuxtRouteMiddleware(async (to, _from) => {
// 서버 사이드에서는 스킵
if (import.meta.server) {
return
}
const gameDataStore = useGameDataStore()
// gameData가 로드되지 않았으면 스킵 (다른 미들웨어에서 로드됨)
if (!gameDataStore.gameData) {
return
}
// 현재 경로에서 언어 코드 추출
// 예: /ko/about/story -> ko
// 예: /en/test/page -> en
const languagePattern = /^\/([a-z]{2})(?:\/|$)/
const match = to.path.match(languagePattern)
const currentLangCode = match ? match[1] : null
// 허용된 언어 코드 목록
const allowedLangCodes = gameDataStore.gameData.lang_codes || []
// 현재 언어가 허용된 언어 목록에 없으면 404로 리다이렉트
if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) {
throw createError({
statusCode: 404,
statusMessage: 'Language not supported',
})
}
})