feat: 점검 작업 중

This commit is contained in:
“hyeonggkim”
2025-10-29 20:56:58 +09:00
parent 7a22fa2287
commit 1003a01dee
26 changed files with 1553 additions and 247 deletions

View File

@@ -6,8 +6,13 @@ import {
} from 'h3'
import { ssrGetFinalLocale } from '../../utils/localeUtil'
import type { GameDataResponse } from '../../types/api/gameData'
import type { ResGetInspectionData } from '../../types/InspectionType'
export default defineEventHandler(async event => {
const config = useRuntimeConfig()
const iBaseApiUrl = `${config.public.stoveApiUrlServer}`
const url = getRequestURL(event)
// 정적 자산, API, 파비콘 등은 제외하고 페이지 요청만 처리
@@ -36,24 +41,12 @@ export default defineEventHandler(async event => {
const config = useRuntimeConfig()
const stoveApiUrlServer = config.public.stoveApiUrlServer
const apiUrl = `${stoveApiUrlServer}/pub-comm/v1.0/template/game`
let inspectionData
const langCode = ssrGetFinalLocale(
event?.node.req.url,
event.node.req.headers
)
// URL의 첫 번째 path를 lang_code로 사용 (파비콘, API 경로 제외)
// const pathSegments = url.pathname
// .split('/')
// .filter(
// segment =>
// segment &&
// !segment.includes('favicon') &&
// !segment.includes('api') &&
// !segment.startsWith('_')
// )
// const langCode = pathSegments[0] || 'ko'
const queryParams: Record<string, string> = {
game_domain: event.context.gameDomain || '',
lang_code: langCode,
@@ -67,8 +60,43 @@ export default defineEventHandler(async event => {
event.context.gameData = response.value
event.context.googleAnalyticsId = response.value?.ga_code
console.log('🚀 ~ gameData:', response.value)
// console.log('🚀 ~ gameData:', response.value)
// 점검 데이터 조회
if (response.value.game_id) {
const inspectionApiUrl = `${iBaseApiUrl}/pub-comm/v3.0/inspection/${response.value.game_id}`
// 직접 $fetch 사용 (composable 사용하지 않음)
const inspectionResponse = await $fetch<ResGetInspectionData>(inspectionApiUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
inspectionData = inspectionResponse?.value?.inspection
// console.log("🚀 ~ inspectionData:", inspectionData)
if (inspectionData?.inspection_status === 0 ) {
/**
* 점검 중인 경우
* - 점검 상태가 1이고 현재 시간이 점검 시작과 종료 사이에 있는지 확인ㄹ
* - 점검 URL 경로가 아닐 경우 no-cache 설정
* - 화이트 리스트 체크
*/
// 현재 경로가 점검 페이지가 아닐 경우 리다이렉트
const inspectionPath = `/${langCode}/inspection`
if (!url.pathname.includes('/inspection')) {
event.node.res.statusCode = 302
event.node.res.setHeader('Location', inspectionPath)
event.node.res.end()
return
}
}
}
}
} catch (error) {
console.error('gameData load error:', error)
}