refactor: 에러 처리 완료, 페이지 접근 api 미들웨어로 수정

This commit is contained in:
“hyeonggkim”
2025-11-11 19:08:58 +09:00
parent 65c79eb689
commit 5c81f5d4d6
12 changed files with 318 additions and 276 deletions

View File

@@ -7,24 +7,29 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
}
// 현재 경로에서 언어 코드 추출
// 예: /ko/about/story -> ko
// 예: /en/test/page -> en
const gameDataStore = useGameDataStore()
const gameData = gameDataStore.gameData as GameDataValue
const langCodes = gameData?.lang_codes
const currentLangCode = csrGetFinalLocale(to.path, langCodes)
const { getPathAfterLanguage } = usePathResolver()
const pageUrl = getPathAfterLanguage(to.path)
// const languagePattern = /^\/([a-z]{2})(?:\/|$)/
// const match = to.path.match(languagePattern)
// const currentLangCode = match ? match[1] : null
console.log("🚀 777777 ~ currentLangCode:", currentLangCode)
//현재 url에서 게임 도메인만 추출
const currentDomain = window.location.hostname
const runtimeConfig = useRuntimeConfig()
// 쿼리스트링에서 f 파라미터 값 추출 (CSR용)
const fValue = (to.query.f as string) || ''
// 미리보기 API 호출 처리
let finalGameDomain = currentDomain
if (fValue === 'preview') {
finalGameDomain = 'samplegame.onstove.com'
}
const req: GameDataRequest = {
gameDomain: `${currentDomain}`,
gameDomain: `${finalGameDomain}`,
langCode: `${currentLangCode}`,
game_alias: '',
lang_code: `${currentLangCode}`,
@@ -34,16 +39,19 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
const { getGameDataExternal } = useGetGameDataExternal()
await getGameDataExternal(req)
// 허용된 언어 코드 목록≈≈
const allowedLangCodes = langCodes || []
// error 페이지는 API 호출하지 않음
if (pageUrl === '/error' || to.path.includes('/error')) {
return
}
// 현재 언어가 허용된 언어 목록에 없으면 에러 페이지로 이동
if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) {
throw createError({
statusCode: 404,
statusMessage: 'Language not supported',
})
return navigateTo(`/${currentLangCode}/error`, { external: false })
// throw createError({
// statusCode: 404,
// statusMessage: 'Language not supported11',
// })
}
})