Merge branch 'feature/20251001-gil' into feature/202501107-all

This commit is contained in:
“hyeonggkim”
2025-11-12 12:55:40 +09:00
4 changed files with 192 additions and 112 deletions

View File

@@ -64,6 +64,7 @@ const { tm } = useI18n()
const props = withDefaults(defineProps<ErrorProps>(), { const props = withDefaults(defineProps<ErrorProps>(), {
error: () => ({}) error: () => ({})
}) })
const router = useRouter()
const nuxtError = useError() const nuxtError = useError()
const currentError = computed(() => props.error || nuxtError.value) const currentError = computed(() => props.error || nuxtError.value)
@@ -79,12 +80,22 @@ const localePath = useLocalePath()
// const handleError = () => clearError({ redirect: '/' }) // const handleError = () => clearError({ redirect: '/' })
const handleError = () => { const handleError = () => {
window.location.href = localePath('/') window.location.href = localePath('/')
// clearError({ redirect: `${localePath('/')}` }) // clearError({ redirect: `${localePath('/brand')}` })
}
const handleBack = () => {
// 에러 상태를 클리어하고 이전 페이지로 이동
// popstate 이벤트가 이미 발생한 경우이므로 추가 동작 불필요
// 키보드 백스페이스의 경우에만 명시적으로 뒤로가기 실행
window.location.href = localePath('/')
// navigateTo(`${router.currentRoute.value.path}`)
} }
// 500 에러 발생 시 /error 페이지로 리다이렉트 // 500 에러 발생 시 /error 페이지로 리다이렉트
onMounted(() => { onMounted(() => {
console.log("🚀 ~ 1111 handleBack ~ router:", router)
console.log("🚀 ~ 2222 router.currentRoute.value.path) ~ router:", router.currentRoute.value.path)
const statusCode = currentError.value?.statusCode const statusCode = currentError.value?.statusCode
console.log("🚀 ~ 2222 currentError==:", currentError.value?.message) console.log("🚀 ~ 2222 currentError==:", currentError.value?.message)
console.log("🚀 ~ 222222 statusCode:", statusCode) console.log("🚀 ~ 222222 statusCode:", statusCode)
@@ -100,6 +111,30 @@ onMounted(() => {
nextTick(() => { nextTick(() => {
isLoading.value = false isLoading.value = false
}) })
// 백스페이스 키 처리
const handleKeydown = (e: KeyboardEvent) => {
console.log("🚀 ~ handleKeydown ~ e:", e.key)
if (e.key === 'Backspace' &&
!['INPUT', 'TEXTAREA'].includes((e.target as HTMLElement).tagName)) {
e.preventDefault()
handleBack()
}
}
// 브라우저 뒤로가기 버튼 처리
const handlePopState = () => {
// clearError()
handleBack()
}
window.addEventListener('keydown', handleKeydown)
window.addEventListener('popstate', handlePopState)
onUnmounted(() => {
window.removeEventListener('keydown', handleKeydown)
window.removeEventListener('popstate', handlePopState)
})
}) })
</script> </script>

View File

@@ -1,57 +1,68 @@
import type { GameDataRequest, GameDataValue } from '#layers/types/api/gameData' import type { GameDataRequest, GameDataValue } from '#layers/types/api/gameData'
export default defineNuxtRouteMiddleware(async (to, _from) => { export default defineNuxtRouteMiddleware(async (to, _from) => {
// 서버 사이드에서는 스킵
if (import.meta.server) { try{
return // 서버 사이드에서는 스킵
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',
// })
}
}) })

View File

@@ -1,68 +1,98 @@
export default defineNuxtRouteMiddleware(async to => { export default defineNuxtRouteMiddleware(async to => {
try { try {
const { getPathAfterLanguage } = usePathResolver()
//error 발생시에는 미들웨어 실행하지 않음 //error 발생시에는 미들웨어 실행하지 않음
//error 객체 조회 //error 객체 조회
if (import.meta.client) { if (!import.meta.client) {
return
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 })
}
} }
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) { } catch (e) {
console.error('[Exception] /middleware/inspection: ', e) console.error('[Exception] /middleware/inspection: ', e)
} }

View File

@@ -30,6 +30,7 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
try { try {
if (to.path.includes('inspection')) { if (to.path.includes('inspection')) {
console.log("🚀 ~ 점검페이지 접근 pageData.global")
return return
} }
@@ -92,6 +93,9 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
if(response?.code === 91003) { if(response?.code === 91003) {
// return navigateTo(`/${langCode}/error`, { external: false }) // return navigateTo(`/${langCode}/error`, { external: false })
//클릭한 주소는 주소표시줄에 표시하도록 수정
window.history.replaceState({}, '', to.path)
// 뒤로가기 이동 시 이전 페이지로 이동되도록 수정
showError(createError({ showError(createError({
statusCode: 404, statusCode: 404,
statusMessage: '페이지를 찾을 수 없어요.', statusMessage: '페이지를 찾을 수 없어요.',