From 5404130324691059acb80bb7008abfe9c7784d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chyeonggkim=E2=80=9D?= <“hyeonggkim@smilegate.com”> Date: Wed, 12 Nov 2025 12:51:39 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=A0=90=EA=B2=80=20=EB=AF=B8?= =?UTF-8?q?=EB=93=A4=EC=9B=A8=EC=96=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layers/middleware/init.route.global.ts | 113 ++++++++++--------- layers/middleware/inspection.ts | 150 +++++++++++++++---------- layers/middleware/pageData.global.ts | 4 + 3 files changed, 156 insertions(+), 111 deletions(-) diff --git a/layers/middleware/init.route.global.ts b/layers/middleware/init.route.global.ts index 61734f2..31ac3f7 100644 --- a/layers/middleware/init.route.global.ts +++ b/layers/middleware/init.route.global.ts @@ -1,57 +1,68 @@ import type { GameDataRequest, GameDataValue } from '#layers/types/api/gameData' export default defineNuxtRouteMiddleware(async (to, _from) => { - // 서버 사이드에서는 스킵 - if (import.meta.server) { - return + + try{ + // 서버 사이드에서는 스킵 + if (import.meta.server) { + return + } + + // 현재 경로에서 언어 코드 추출 + 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) + + //현재 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: `${finalGameDomain}`, + langCode: `${currentLangCode}`, + game_alias: '', + lang_code: `${currentLangCode}`, + baseApiUrl: `${runtimeConfig.public.stoveApiUrl}`, + gameId: '', + } + const { getGameDataExternal } = useGetGameDataExternal() + await getGameDataExternal(req) + + + // error 페이지는 API 호출하지 않음 + if (pageUrl === '/error' || to.path.includes('/error') || to.path.includes('/inspection')) { + return + } + + // 허용된 언어 코드 목록≈≈ + const allowedLangCodes = langCodes || [] + + // 현재 언어가 허용된 언어 목록에 없으면 에러 페이지로 이동 + if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) { + return navigateTo(`/${currentLangCode}/error`, { external: true }) + + } + } catch (error) { + console.error(error) + showError(createError({ + statusCode: error.statusCode, + statusMessage: error.message, + fatal: false, // 즉시 에러 페이지로 + data: { reason: 'post-not-found' } + })) } - // 현재 경로에서 언어 코드 추출 - 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) - - - //현재 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: `${finalGameDomain}`, - langCode: `${currentLangCode}`, - game_alias: '', - lang_code: `${currentLangCode}`, - baseApiUrl: `${runtimeConfig.public.stoveApiUrl}`, - gameId: '', - } - const { getGameDataExternal } = useGetGameDataExternal() - await getGameDataExternal(req) - - // 허용된 언어 코드 목록≈≈ - const allowedLangCodes = langCodes || [] - - // error 페이지는 API 호출하지 않음 - if (pageUrl === '/error' || to.path.includes('/error')) { - return - } - // 현재 언어가 허용된 언어 목록에 없으면 에러 페이지로 이동 - if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) { - return navigateTo(`/${currentLangCode}/error`, { external: false }) - // throw createError({ - // statusCode: 404, - // statusMessage: 'Language not supported11', - // }) - } + }) diff --git a/layers/middleware/inspection.ts b/layers/middleware/inspection.ts index 0319231..26492f7 100644 --- a/layers/middleware/inspection.ts +++ b/layers/middleware/inspection.ts @@ -1,68 +1,98 @@ export default defineNuxtRouteMiddleware(async to => { try { + const { getPathAfterLanguage } = usePathResolver() //error 발생시에는 미들웨어 실행하지 않음 //error 객체 조회 - if (import.meta.client) { - - const error = useError() - if(error.value?.statusCode){ - return showError(createError({ - statusCode: error.value?.statusCode, - statusMessage: error.value?.message, - fatal: true, - // data: { path: to.path } - })) - } - - const gameDataStore = useGameDataStore() - const runtimeConfig = useRuntimeConfig() - - const { gameData } = storeToRefs(gameDataStore) - // const baseDomain = `${runtimeConfig.public.baseDomain}` - const stoveApiBaseUrl = runtimeConfig.public.stoveApiUrl - const stoveGameId = gameData.value.game_id - // const stoveMaintenanceApiUrl = `${runtimeConfig.public.stoveMaintenanceApiUrl}` - - // const localeCookie = useCookie('LOCALE', { - // domain: baseDomain - // }) - - const finalLocale = csrGetFinalLocale(to.path, gameData.value.lang_codes) - // localeCookie.value = finalLocale.toUpperCase() - - // 웹 점검 ----- - const { isWebInspection, getInspectionDataExternal } = - useGetInspectionDataExternal() - await getInspectionDataExternal({ - baseApiUrl: stoveApiBaseUrl, - gameId: stoveGameId, - }) - - // 게임 점검 ----- - // const { checkGameMaintenance } = useGetGameMaintenance() - // await checkGameMaintenance({ - // baseApiUrl: stoveMaintenanceApiUrl, - // category: 'GAME', - // service_id1: stoveGameId, - // lang: `${finalLocale}`.toLowerCase() - // }) - - if ( - isWebInspection.value && - !to.path.includes('inspection') && - !to.path.includes('api') - ) { - // 점검 중인 경우 - return navigateTo(`/${finalLocale}/inspection`, { external: true }) - } else if ( - !isWebInspection.value && - to.path?.indexOf('inspection') !== -1 - ) { - // 점검이 종료된 후 점검 페이지 접근시 메인으로 리다이렉트 - return navigateTo(`/${finalLocale}`, { external: true }) - } - + if (!import.meta.client) { + return } + + const pageUrl = getPathAfterLanguage(to.path) + + // error 페이지는 API 호출하지 않음 + if (pageUrl === '/error' || to.path.includes('/error')) { + return + } + + const gameDataStore = useGameDataStore() + const runtimeConfig = useRuntimeConfig() + + const { gameData } = storeToRefs(gameDataStore) + // const baseDomain = `${runtimeConfig.public.baseDomain}` + const stoveApiBaseUrl = runtimeConfig.public.stoveApiUrl + const stoveGameId = gameData.value.game_id + // const stoveMaintenanceApiUrl = `${runtimeConfig.public.stoveMaintenanceApiUrl}` + + // const localeCookie = useCookie('LOCALE', { + // domain: baseDomain + // }) + + const finalLocale = csrGetFinalLocale(to.path, gameData.value.lang_codes) + // localeCookie.value = finalLocale.toUpperCase() + + // 웹 점검 ----- + const { isWebInspection, getInspectionDataExternal } = useGetInspectionDataExternal() + + await getInspectionDataExternal({ + baseApiUrl: stoveApiBaseUrl, + gameId: stoveGameId, + }) + console.log("🚀 ~ stoveApiBaseUrl:", stoveApiBaseUrl) + console.log("🚀 ~ stoveGameId:", stoveGameId) + + // 게임 점검 ----- + // const { checkGameMaintenance } = useGetGameMaintenance() + // await checkGameMaintenance({ + // baseApiUrl: stoveMaintenanceApiUrl, + // category: 'GAME', + // service_id1: stoveGameId, + // lang: `${finalLocale}`.toLowerCase() + // }) + + // 테스트 수정 + // isWebInspection.value === + // if ( + // !isWebInspection.value && + // !to.path.includes('inspection') && + // !to.path.includes('api') + // ) { + // console.log("🚀 ~ 점검 중인 경우") + // // 점검 중인 경우 + // return navigateTo(`/${finalLocale}/inspection`, { external: true }) + // } else if ( isWebInspection.value && !to.path.includes('inspection') ) { + // // 점검이 종료된 후 점검 페이지 접근시 메인으로 리다이렉트 + // console.log("🚀 ~ 점검이 종료된 후 점검 페이지 접근시 메인으로 리다이렉트") + // return navigateTo(`/${finalLocale}`, { external: true }) + // } + + if ( + isWebInspection.value === true && + !to.path.includes('inspection') && + !to.path.includes('api') + ) { + // 점검 중인 경우 + return navigateTo(`/${finalLocale}/inspection`, { external: true }) + } else if ( + !isWebInspection.value && + to.path?.indexOf('inspection') !== -1 + ) { + // 점검이 종료된 후 점검 페이지 접근시 메인으로 리다이렉트 + return navigateTo(`/${finalLocale}`, { external: true }) + } + + //이동한 페이지는 에러 페이지로 리다이렉트 + + const error = useError() + if(error.value?.statusCode){ + return showError(createError({ + statusCode: error.value?.statusCode, + statusMessage: error.value?.message, + fatal: true, + data: { path: to.path } + })) + } + + } catch (e) { console.error('[Exception] /middleware/inspection: ', e) } diff --git a/layers/middleware/pageData.global.ts b/layers/middleware/pageData.global.ts index bd71ac4..4dcc817 100644 --- a/layers/middleware/pageData.global.ts +++ b/layers/middleware/pageData.global.ts @@ -30,6 +30,7 @@ export default defineNuxtRouteMiddleware(async (to, _from) => { try { if (to.path.includes('inspection')) { + console.log("🚀 ~ 점검페이지 접근 pageData.global") return } @@ -92,6 +93,9 @@ export default defineNuxtRouteMiddleware(async (to, _from) => { if(response?.code === 91003) { // return navigateTo(`/${langCode}/error`, { external: false }) + //클릭한 주소는 주소표시줄에 표시하도록 수정 + window.history.replaceState({}, '', to.path) + // 뒤로가기 이동 시 이전 페이지로 이동되도록 수정 showError(createError({ statusCode: 404, statusMessage: '페이지를 찾을 수 없어요.',