fix. 개발 도구 적용. (typescript, prettier, es-lint)
This commit is contained in:
@@ -3,67 +3,70 @@ import {
|
||||
getRequestHost,
|
||||
defineEventHandler,
|
||||
getRequestURL,
|
||||
} from "h3";
|
||||
} from 'h3'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const url = getRequestURL(event);
|
||||
export default defineEventHandler(async event => {
|
||||
const url = getRequestURL(event)
|
||||
|
||||
// 정적 자산, API, 파비콘 등은 제외하고 페이지 요청만 처리
|
||||
if (
|
||||
url.pathname.startsWith("/api/") ||
|
||||
url.pathname.startsWith("/_nuxt/") ||
|
||||
url.pathname.startsWith("/favicon") ||
|
||||
url.pathname.includes(".") ||
|
||||
url.pathname.startsWith("/_")
|
||||
url.pathname.startsWith('/api/') ||
|
||||
url.pathname.startsWith('/_nuxt/') ||
|
||||
url.pathname.startsWith('/favicon') ||
|
||||
url.pathname.includes('.') ||
|
||||
url.pathname.startsWith('/_')
|
||||
) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
const host =
|
||||
(getHeader(event, "host") || getRequestHost(event)).toString() || "";
|
||||
const baseDomain = process.env.BASE_DOMAIN || ".onstove.com";
|
||||
const isGameAliasExtractable = host.includes(baseDomain);
|
||||
(getHeader(event, 'host') || getRequestHost(event)).toString() || ''
|
||||
const baseDomain = process.env.BASE_DOMAIN || '.onstove.com'
|
||||
const isGameAliasExtractable = host.includes(baseDomain)
|
||||
|
||||
if (isGameAliasExtractable) {
|
||||
const gameAlias = host.split(".")[0];
|
||||
const gameAlias = host.split('.')[0]
|
||||
|
||||
if (gameAlias && gameAlias !== "www") {
|
||||
event.context.gameAlias = gameAlias;
|
||||
if (gameAlias && gameAlias !== 'www') {
|
||||
event.context.gameAlias = gameAlias
|
||||
}
|
||||
}
|
||||
|
||||
// gameData를 직접 가져와서 context에 저장 (API 호출 없이)
|
||||
try {
|
||||
const config = useRuntimeConfig();
|
||||
const stoveApiBaseUrl = config.public.stoveApiUrl;
|
||||
const apiUrl = `${stoveApiBaseUrl}/pub-comm/v1.0/template/game`;
|
||||
const config = useRuntimeConfig()
|
||||
const stoveApiBaseUrl = config.public.stoveApiUrl
|
||||
const apiUrl = `${stoveApiBaseUrl}/pub-comm/v1.0/template/game`
|
||||
|
||||
// URL의 첫 번째 path를 lang_code로 사용 (파비콘, API 경로 제외)
|
||||
const url = getRequestURL(event);
|
||||
const url = getRequestURL(event)
|
||||
const pathSegments = url.pathname
|
||||
.split("/")
|
||||
.split('/')
|
||||
.filter(
|
||||
(segment) =>
|
||||
segment =>
|
||||
segment &&
|
||||
!segment.includes("favicon") &&
|
||||
!segment.includes("api") &&
|
||||
!segment.startsWith("_")
|
||||
);
|
||||
const langCode = pathSegments[0] || "ko";
|
||||
!segment.includes('favicon') &&
|
||||
!segment.includes('api') &&
|
||||
!segment.startsWith('_')
|
||||
)
|
||||
const langCode = pathSegments[0] || 'ko'
|
||||
|
||||
const queryParams: Record<string, string> = {
|
||||
game_alias: event.context.gameAlias || "",
|
||||
game_alias: event.context.gameAlias || '',
|
||||
lang_code: langCode,
|
||||
};
|
||||
}
|
||||
|
||||
const response = await $fetch(apiUrl, {
|
||||
query: queryParams,
|
||||
});
|
||||
})
|
||||
|
||||
if (response?.code === 0 && "value" in response) {
|
||||
event.context.gameData = response.value;
|
||||
// 타입 단언을 사용하여 response의 타입 오류를 해결
|
||||
const res = response as { code?: number; value?: unknown }
|
||||
|
||||
if (res?.code === 0 && 'value' in res) {
|
||||
event.context.gameData = res.value
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("gameData load error:", error);
|
||||
console.error('gameData load error:', error)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user