Files
web-temp/layers/middleware/inspection.ts
2025-12-08 10:16:52 +09:00

99 lines
3.2 KiB
TypeScript

export default defineNuxtRouteMiddleware(async to => {
try {
//error 발생시에는 미들웨어 실행하지 않음
//error 객체 조회
if (!import.meta.client) {
return
}
const { getPathAfterLanguage } = usePathResolver()
const pageUrl = getPathAfterLanguage(to.path)
// error 페이지는 API 호출하지 않음
if (pageUrl === '/error' || to.path.includes('/error')) {
console.log("🚀 ~ inspection error 페이지는 API 호출하지 않음")
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,
})
// 게임 점검 -----
// 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) {
console.error('[Exception] /middleware/inspection: ', e)
}
})