Files
web-temp/layers/middleware/inspection.ts
2025-11-07 12:55:00 +09:00

57 lines
1.9 KiB
TypeScript

export default defineNuxtRouteMiddleware(async to => {
try {
if (import.meta.client) {
const gameDataStore = useGameDataStore()
const { gameData } = storeToRefs(gameDataStore)
console.log('🚀 ~ 00000 gameData:', gameData.value)
const runtimeConfig = useRuntimeConfig()
// 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 })
}
}
} catch (e) {
console.error('[Exception] /middleware/inspection: ', e)
}
})