refactor: 점검 미들웨어 수정
This commit is contained in:
@@ -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',
|
|
||||||
// })
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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: '페이지를 찾을 수 없어요.',
|
||||||
|
|||||||
Reference in New Issue
Block a user