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,6 +1,8 @@
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) => {
try{
// 서버 사이드에서는 스킵 // 서버 사이드에서는 스킵
if (import.meta.server) { if (import.meta.server) {
return return
@@ -14,7 +16,6 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
const { getPathAfterLanguage } = usePathResolver() const { getPathAfterLanguage } = usePathResolver()
const pageUrl = getPathAfterLanguage(to.path) const pageUrl = getPathAfterLanguage(to.path)
//현재 url에서 게임 도메인만 추출 //현재 url에서 게임 도메인만 추출
const currentDomain = window.location.hostname const currentDomain = window.location.hostname
const runtimeConfig = useRuntimeConfig() const runtimeConfig = useRuntimeConfig()
@@ -39,19 +40,29 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
const { getGameDataExternal } = useGetGameDataExternal() const { getGameDataExternal } = useGetGameDataExternal()
await getGameDataExternal(req) await getGameDataExternal(req)
// error 페이지는 API 호출하지 않음
if (pageUrl === '/error' || to.path.includes('/error') || to.path.includes('/inspection')) {
return
}
// 허용된 언어 코드 목록≈≈ // 허용된 언어 코드 목록≈≈
const allowedLangCodes = langCodes || [] const allowedLangCodes = langCodes || []
// error 페이지는 API 호출하지 않음
if (pageUrl === '/error' || to.path.includes('/error')) {
return
}
// 현재 언어가 허용된 언어 목록에 없으면 에러 페이지로 이동 // 현재 언어가 허용된 언어 목록에 없으면 에러 페이지로 이동
if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) { if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) {
return navigateTo(`/${currentLangCode}/error`, { external: false }) return navigateTo(`/${currentLangCode}/error`, { external: true })
// throw createError({
// statusCode: 404,
// statusMessage: 'Language not supported11',
// })
} }
} catch (error) {
console.error(error)
showError(createError({
statusCode: error.statusCode,
statusMessage: error.message,
fatal: false, // 즉시 에러 페이지로
data: { reason: 'post-not-found' }
}))
}
}) })

View File

@@ -1,17 +1,17 @@
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() const pageUrl = getPathAfterLanguage(to.path)
if(error.value?.statusCode){
return showError(createError({ // error 페이지는 API 호출하지 않음
statusCode: error.value?.statusCode, if (pageUrl === '/error' || to.path.includes('/error')) {
statusMessage: error.value?.message, return
fatal: true,
// data: { path: to.path }
}))
} }
const gameDataStore = useGameDataStore() const gameDataStore = useGameDataStore()
@@ -31,12 +31,14 @@ export default defineNuxtRouteMiddleware(async to => {
// localeCookie.value = finalLocale.toUpperCase() // localeCookie.value = finalLocale.toUpperCase()
// 웹 점검 ----- // 웹 점검 -----
const { isWebInspection, getInspectionDataExternal } = const { isWebInspection, getInspectionDataExternal } = useGetInspectionDataExternal()
useGetInspectionDataExternal()
await getInspectionDataExternal({ await getInspectionDataExternal({
baseApiUrl: stoveApiBaseUrl, baseApiUrl: stoveApiBaseUrl,
gameId: stoveGameId, gameId: stoveGameId,
}) })
console.log("🚀 ~ stoveApiBaseUrl:", stoveApiBaseUrl)
console.log("🚀 ~ stoveGameId:", stoveGameId)
// 게임 점검 ----- // 게임 점검 -----
// const { checkGameMaintenance } = useGetGameMaintenance() // const { checkGameMaintenance } = useGetGameMaintenance()
@@ -47,8 +49,24 @@ export default defineNuxtRouteMiddleware(async to => {
// lang: `${finalLocale}`.toLowerCase() // 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 ( if (
isWebInspection.value && isWebInspection.value === true &&
!to.path.includes('inspection') && !to.path.includes('inspection') &&
!to.path.includes('api') !to.path.includes('api')
) { ) {
@@ -62,7 +80,19 @@ export default defineNuxtRouteMiddleware(async to => {
return navigateTo(`/${finalLocale}`, { external: true }) 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: '페이지를 찾을 수 없어요.',