refactor: 언어 정책 쿠키 i18n에서 설정, gameData External 제거

This commit is contained in:
“hyeonggkim”
2025-11-13 18:46:03 +09:00
parent 4698efc225
commit 4b7ccd8f4f
7 changed files with 98 additions and 83 deletions

View File

@@ -1,15 +1,27 @@
import type { GameDataRequest, GameDataValue } from '#layers/types/api/gameData'
export default defineNuxtRouteMiddleware(async (to, _from) => {
const nuxtApp = useNuxtApp()
const getGameDataFromServer = (): GameDataValue | null => {
return import.meta.server
? (nuxtApp.ssrContext?.event.context.gameData ?? null)
: null
}
const serverGameData = getGameDataFromServer()
const gameDataStore = useGameDataStore()
const { setGameData } = gameDataStore
if (serverGameData) {
setGameData(serverGameData)
}
try{
// 서버 사이드에서는 스킵
if (import.meta.server) {
if (!import.meta.client) {
return
}
// 현재 경로에서 언어 코드 추출
const gameDataStore = useGameDataStore()
const gameData = gameDataStore.gameData as GameDataValue
const langCodes = gameData?.lang_codes
const currentLangCode = csrGetFinalLocale(to.path, langCodes)
@@ -17,28 +29,28 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
const pageUrl = getPathAfterLanguage(to.path)
//현재 url에서 게임 도메인만 추출
const currentDomain = window.location.hostname
const runtimeConfig = useRuntimeConfig()
// const currentDomain = window.location.hostname
// const runtimeConfig = useRuntimeConfig()
// 쿼리스트링에서 f 파라미터 값 추출 (CSR용)
const fValue = (to.query.f as string) || ''
// const fValue = (to.query.f as string) || ''
// 미리보기 API 호출 처리
let finalGameDomain = currentDomain
if (fValue === 'preview') {
finalGameDomain = 'samplegame.onstove.com'
}
// 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 req: GameDataRequest = {
// gameDomain: `${finalGameDomain}`,
// langCode: `${currentLangCode}`,
// game_alias: '',
// lang_code: `${currentLangCode}`,
// baseApiUrl: `${runtimeConfig.public.stoveApiUrl}`,
// gameId: '',
// }
// const { getGameDataExternal } = useGetGameDataExternal()
// await getGameDataExternal(req)
// error 페이지는 API 호출하지 않음