refactor: 언어 정책 쿠키 i18n에서 설정, gameData External 제거
This commit is contained in:
@@ -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 호출하지 않음
|
||||
|
||||
@@ -16,16 +16,17 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
const store = usePageDataStore()
|
||||
const gameDomain = useGetGameDomain()
|
||||
const { getPathAfterLanguage } = usePathResolver()
|
||||
const headers = useRequestHeaders()
|
||||
const gameDataStore = useGameDataStore()
|
||||
const gameData = gameDataStore.gameData as GameDataValue
|
||||
console.log("🚀 ~ gameDomain:", gameDomain)
|
||||
|
||||
const langCode = ssrGetFinalLocale(
|
||||
const langCode = csrGetFinalLocale(
|
||||
to.path,
|
||||
headers,
|
||||
gameData?.lang_codes,
|
||||
gameData?.default_lang_code
|
||||
)
|
||||
console.log("🚀 ~ to.path:", to.path)
|
||||
console.log("🚀 ~ langCode:", gameData?.lang_codes)
|
||||
console.log("🚀 ~ langCode:", langCode)
|
||||
|
||||
try {
|
||||
|
||||
@@ -35,17 +36,18 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
}
|
||||
|
||||
const pageUrl = getPathAfterLanguage(to.path)
|
||||
|
||||
// error 페이지는 API 호출하지 않음
|
||||
if (pageUrl === '/error' || to.path.includes('/error')) {
|
||||
return
|
||||
}
|
||||
console.log("🚀 ~ pageUrl:", pageUrl)
|
||||
|
||||
// pageUrl이 빈값이거나 null이면 /brand로 리다이렉트
|
||||
if (!pageUrl || pageUrl === '' || pageUrl === '/' || pageUrl === `/${langCode}/`) {
|
||||
return navigateTo(`/${langCode}/brand`, { external: false })
|
||||
}
|
||||
|
||||
|
||||
// error 페이지는 API 호출하지 않음
|
||||
if (pageUrl === '/error' || to.path.includes('/error')) {
|
||||
return
|
||||
}
|
||||
const accessToken = csrGetAccessToken()
|
||||
|
||||
const headers = {
|
||||
@@ -53,16 +55,16 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
}
|
||||
|
||||
// 쿼리스트링에서 f 파라미터 값 추출 (CSR용)
|
||||
const fValue = (to.query.f as string) || ''
|
||||
// const fValue = (to.query.f as string) || ''
|
||||
|
||||
// 미리보기 API 호출 처리
|
||||
let finalGameDomain = gameDomain
|
||||
if (fValue === 'preview') {
|
||||
finalGameDomain = 'samplegame.onstove.com'
|
||||
}
|
||||
// // 미리보기 API 호출 처리
|
||||
// let finalGameDomain = gameDomain
|
||||
// if (fValue === 'preview') {
|
||||
// finalGameDomain = 'samplegame.onstove.com'
|
||||
// }
|
||||
|
||||
const queryParams: Record<string, string> = {
|
||||
game_domain: finalGameDomain,
|
||||
game_domain: gameDomain,
|
||||
lang_code: langCode,
|
||||
page_url: pageUrl,
|
||||
_t: Date.now().toString(), // 캐시 무효화를 위한 타임스탬프
|
||||
|
||||
Reference in New Issue
Block a user