70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
export default defineNuxtRouteMiddleware(async to => {
|
|
try {
|
|
//error 발생시에는 미들웨어 실행하지 않음
|
|
//error 객체 조회
|
|
if (import.meta.client) {
|
|
|
|
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 })
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
console.error('[Exception] /middleware/inspection: ', e)
|
|
}
|
|
})
|