refactor. 패키지 및 의존성 업데이트

- @pinia/nuxt 및 pinia 버전 업데이트
- app.vue에서 favicon 링크 생성 로직 개선
- error.vue에서 불필요한 console.log 제거
- pageData.global.ts에서 API URL 수정 및 에러 처리 로직 개선
- init-game-data.server.ts에서 언어 코드 설정 로직 개선
- gameData.ts에서 경로 필터링 로직 수정
- commonUtil.ts에서 정적 파일 확인 정규 표현식 개선
This commit is contained in:
clkim
2026-03-26 18:24:17 +09:00
parent 4f83ae2311
commit d5e783113d
8 changed files with 233 additions and 76 deletions

View File

@@ -49,7 +49,7 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
const pageVer = urlParams.get('page_ver') || ''
const queryLangCode = urlParams.get('lang_code') || currentLangCode
apiUrl = `${stoveApiBaseUrl}/pub-comm/v1.0/template/page/preview`
apiUrl = `${stoveApiOrigin}/pub-comm/v1.0/template/page/preview`
queryParams = {
lang_code: queryLangCode,
page_seq: pageSeq,
@@ -72,7 +72,7 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
} catch (error) {
pageDataStore.clearPageData()
console.error(error)
return showError(
return abortNavigation(
createError({
statusCode: error.statusCode,
statusMessage: error.message,
@@ -95,14 +95,12 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
pageDataResponse?.code === 91001 ||
pageDataResponse?.code === 91003
) {
return showError(
return abortNavigation(
createError({
statusCode: 404,
statusMessage: pageDataResponse?.message,
fatal: false, // 즉시 에러 페이지로
data: {
reason: pageDataResponse?.message,
},
statusMessage: pageDataResponse?.message,
data: { reason: 'post-not-found' },
})
)
}
@@ -110,14 +108,16 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
if (pageDataResponse?.code === 91002) {
// 이미 /home 경로에 있으면 무한 리다이렉트 방지
if (pathWithoutLocale === '/home') {
return createError({
statusCode: 404,
statusMessage: pageDataResponse?.message,
fatal: false, // 즉시 에러 페이지로
data: {
reason: pageDataResponse?.message,
},
})
return abortNavigation(
createError({
statusCode: 404,
statusMessage: pageDataResponse?.message,
fatal: false, // 즉시 에러 페이지로
data: {
reason: 'invalid-lang-code',
},
})
)
}
return navigateTo(`/${currentLangCode}/home`)
}

View File

@@ -3,18 +3,22 @@ import type { GameDataValue } from '#layers/types/api/gameData'
export default defineNuxtPlugin({
name: 'hydrate-game-data',
dependsOn: ['pinia'],
setup(_nuxtApp) {
async setup(_nuxtApp) {
if (!import.meta.server) return
const event = useRequestEvent()
const gameData = (event?.context as { gameData?: GameDataValue })?.gameData
const currentLangCode = (event?.context as { currentLangCode?: string })
?.currentLangCode
const eventContext = event?.context as {
gameData?: GameDataValue
currentLangCode?: string
}
const gameData = eventContext?.gameData
const resolvedCurrentLangCode = eventContext?.currentLangCode || null
if (!gameData) return
const gameDataStore = useGameDataStore()
gameDataStore.setCurrentLangCode(currentLangCode)
gameDataStore.setGameData(gameData)
gameDataStore.setCurrentLangCode(resolvedCurrentLangCode)
},
})

View File

@@ -115,7 +115,7 @@ function fnLocaleMiddleware(
function shouldSkipPath(path: string): boolean {
return (
path.startsWith('/_nuxt/') ||
path.startsWith('/__nuxt') ||
(path.startsWith('/__nuxt') && !path.startsWith('/__nuxt_error')) ||
path.startsWith('/api/') ||
path.startsWith('/_i18n/') ||
path.includes('/assets/') ||
@@ -128,15 +128,14 @@ function shouldSkipPath(path: string): boolean {
export default defineEventHandler(async event => {
const runtimeConfig = useRuntimeConfig()
// HMR 요청 필터링 (개발 모드에서 중복 실행 방지)
if (shouldSkipPath(event.path)) {
return
}
// 1-1. 정적 파일 패스
if (isStaticFile(event.path)) return
// 1-2. 특정 경로 패스 (API, 리소스)
if (shouldSkipPath(event.path)) return
// 이미 응답이 종료되었는지 확인 (리다이렉트 등으로 인한 중복 실행 방지)
if (event.node.res.headersSent || event.node.res.writableEnded) {
return
}
if (event.node.res.headersSent || event.node.res.writableEnded) return
const stoveApiServerBaseUrl = runtimeConfig.public.stoveApiUrlServer
@@ -179,15 +178,12 @@ export default defineEventHandler(async event => {
// -------------------------------------------------------------------------------
const fullPath = event.path
// 1-1. 정적 파일 패스
if (isStaticFile(event.path)) return
// error 패스
if (fullPath.startsWith('/__nuxt_error')) return
// 1-2. /inspection 패스
// inspection 패스
if (fullPath.includes('/inspection')) return
// 1-3. 특정 경로 패스 (API, 리소스)
if (shouldSkipPath(fullPath)) return
// 캐시 키 생성 (게임 ID 포함하여 충돌 방지)
const gameId = gameDataValue?.game_id || 'default'
const cacheKey = `inspection:${gameId}`

View File

@@ -147,7 +147,7 @@ const setCookieForDay = (name: string, value: string, exp?: number) => {
// 정적 파일인지 확인하는 함수
const isStaticFile = (path: string): boolean => {
return /\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|scss)$/i.test(
return /\.(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf|eot|scss)$/i.test(
path
)
}