feat: 미리보기 api 호출 추가, 에러 코드 추가
This commit is contained in:
@@ -11,7 +11,6 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
|
||||
const runtimeConfig = useRuntimeConfig()
|
||||
const stoveApiBaseUrl = runtimeConfig.public.stoveApiUrl
|
||||
const apiUrl = `${stoveApiBaseUrl}/pub-comm/v2.0/template/page`
|
||||
|
||||
const gameDomain = useGetGameDomain()
|
||||
const gameDataStore = useGameDataStore()
|
||||
@@ -107,20 +106,33 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
}
|
||||
|
||||
// 쿼리스트링에서 f 파라미터 값 추출 (CSR용)
|
||||
// const fValue = (to.query.f as string) || ''
|
||||
// 미리보기 쿼리스트링에서 파라미터 값 추출
|
||||
// preview?page_seq=1&page_ver=1&lang_code=ko
|
||||
const queryString = to.fullPath.includes('?') ? to.fullPath.split('?')[1] : ''
|
||||
const urlParams = new URLSearchParams(queryString)
|
||||
const pageSeq = urlParams.get('page_seq') || ''
|
||||
const pageVer = urlParams.get('page_ver') || ''
|
||||
const queryLangCode = urlParams.get('lang_code') || langCode
|
||||
|
||||
// // 미리보기 API 호출 처리
|
||||
// let finalGameDomain = gameDomain
|
||||
// if (fValue === 'preview') {
|
||||
// finalGameDomain = 'samplegame.onstove.com'
|
||||
// }
|
||||
|
||||
const queryParams: Record<string, string> = {
|
||||
game_domain: gameDomain,
|
||||
lang_code: langCode,
|
||||
page_url: pageUrl,
|
||||
_t: Date.now().toString(), // 캐시 무효화를 위한 타임스탬프
|
||||
let queryParams: Record<string, string>;
|
||||
let apiUrl: string;
|
||||
if (pageUrl === '/preview') {
|
||||
apiUrl = `${stoveApiBaseUrl}/pub-comm/v1.0/template/page/preview`
|
||||
queryParams = {
|
||||
lang_code: queryLangCode,
|
||||
page_seq: pageSeq,
|
||||
page_ver: pageVer,
|
||||
_t: Date.now().toString(), // 캐시 무효화를 위한 타임스탬프
|
||||
}
|
||||
|
||||
} else {
|
||||
apiUrl = `${stoveApiBaseUrl}/pub-comm/v2.0/template/page`
|
||||
queryParams = {
|
||||
game_domain: gameDomain,
|
||||
lang_code: langCode,
|
||||
page_url: pageUrl,
|
||||
_t: Date.now().toString(), // 캐시 무효화를 위한 타임스탬프
|
||||
}
|
||||
}
|
||||
|
||||
const response = (await commonFetch('GET', apiUrl, {
|
||||
@@ -145,7 +157,13 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
})
|
||||
}
|
||||
|
||||
if (response?.code === 91002 && response?.message === 'Invalid LangCode') {
|
||||
// 404 에러 코드 체크
|
||||
const isNotFoundError =
|
||||
(response?.code === 91002 && response?.message === 'Invalid LangCode') ||
|
||||
response?.code === 91003 ||
|
||||
response?.code === 90004
|
||||
|
||||
if (isNotFoundError) {
|
||||
//클릭한 주소는 주소표시줄에 표시하도록 수정
|
||||
if (import.meta.client) {
|
||||
window.history.replaceState({}, '', to.path)
|
||||
@@ -154,15 +172,14 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
showError(
|
||||
createError({
|
||||
statusCode: 404,
|
||||
statusMessage: '페이지를 찾을 수 없어요.',
|
||||
statusMessage: response?.message,
|
||||
fatal: false, // 즉시 에러 페이지로
|
||||
data: { reason: 'post-not-found Invalid LangCode' },
|
||||
data: { reason: response?.message },
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (response?.code === 91003) {
|
||||
// return navigateTo(`/${langCode}/error`, { external: false })
|
||||
if (response?.code === 90002) {
|
||||
//클릭한 주소는 주소표시줄에 표시하도록 수정
|
||||
if (import.meta.client) {
|
||||
window.history.replaceState({}, '', to.path)
|
||||
@@ -170,10 +187,10 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
// 뒤로가기 이동 시 이전 페이지로 이동되도록 수정
|
||||
showError(
|
||||
createError({
|
||||
statusCode: 404,
|
||||
statusMessage: '페이지를 찾을 수 없어요.',
|
||||
statusCode: 500,
|
||||
statusMessage: response?.message,
|
||||
fatal: false, // 즉시 에러 페이지로
|
||||
data: { reason: 'post-not-found' },
|
||||
data: { reason: response?.message },
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -256,25 +256,6 @@ export default defineEventHandler(async event => {
|
||||
initLangCodes,
|
||||
initDefaultLocale
|
||||
)
|
||||
|
||||
// 쿼리스트링에서 f 파라미터 값 추출
|
||||
const path = event?.node.req.url || ''
|
||||
let fValue = ''
|
||||
if (path.includes('?')) {
|
||||
try {
|
||||
const queryString = path.split('?')[1]
|
||||
const urlParams = new URLSearchParams(queryString)
|
||||
fValue = urlParams.get('f') || ''
|
||||
} catch (e) {
|
||||
console.error('쿼리스트링 파싱 에러:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 미리보기 API 호출 처리
|
||||
if (fValue === 'preview') {
|
||||
cleanHost = 'samplegame.onstove.com'
|
||||
}
|
||||
|
||||
const queryParams: Record<string, string> = {
|
||||
game_domain: cleanHost || '',
|
||||
lang_code: finalLocale,
|
||||
@@ -313,20 +294,25 @@ export default defineEventHandler(async event => {
|
||||
} else {
|
||||
// 점검 데이터 조회
|
||||
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)
|
||||
cache.set(cacheKey, inspectionData) // 캐시에 저장
|
||||
try {
|
||||
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)
|
||||
cache.set(cacheKey, inspectionData) // 캐시에 저장
|
||||
} catch (error) {
|
||||
console.error('inspection data load error:', error)
|
||||
// 에러 발생 시 inspectionData는 undefined로 유지
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user