59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
export default defineNuxtRouteMiddleware(async to => {
|
|
const runtimeConfig = useRuntimeConfig()
|
|
|
|
// server에서는 실행X -----
|
|
if (import.meta.server) return
|
|
|
|
// error 페이지는 실행X -----
|
|
if (to.path.includes('/error')) return
|
|
|
|
try {
|
|
const gameDataStore = useGameDataStore()
|
|
const { gameId, langCodes } = storeToRefs(gameDataStore)
|
|
|
|
// app.vue에서 설정한 스토어 값이 없으면 대기
|
|
if (!gameId.value || !langCodes.value) return
|
|
|
|
const stoveApiBaseUrl = `${runtimeConfig.public.stoveApiUrl}`
|
|
// const baseDomain = `${runtimeConfig.public.baseDomain}`
|
|
// const stoveMaintenanceApiUrl = `${runtimeConfig.public.stoveMaintenanceApiUrl}`
|
|
const stoveGameId = gameId.value
|
|
|
|
const finalLocale = csrGetFinalLocale(to.path, langCodes.value)
|
|
|
|
// 웹 점검 -----
|
|
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)
|
|
}
|
|
})
|