36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { useGameDataStore } from "#layers/stores/useGameDataStore";
|
|
|
|
export default defineNuxtRouteMiddleware(async (to, from) => {
|
|
// 서버 사이드에서는 스킵
|
|
if (import.meta.server) {
|
|
return;
|
|
}
|
|
|
|
const gameDataStore = useGameDataStore();
|
|
|
|
// gameData가 로드되지 않았으면 스킵 (다른 미들웨어에서 로드됨)
|
|
if (!gameDataStore.gameData) {
|
|
return;
|
|
}
|
|
|
|
// 현재 경로에서 언어 코드 추출
|
|
// 예: /ko/about/story -> ko
|
|
// 예: /en/test/page -> en
|
|
const languagePattern = /^\/([a-z]{2})(?:\/|$)/;
|
|
const match = to.path.match(languagePattern);
|
|
const currentLangCode = match ? match[1] : null;
|
|
console.log("🚀 3333~ currentLangCode:", currentLangCode)
|
|
|
|
// 허용된 언어 코드 목록
|
|
const allowedLangCodes = gameDataStore.gameData.lang_codes || [];
|
|
console.log("🚀 ~ allowedLangCodes:", allowedLangCodes)
|
|
|
|
// 현재 언어가 허용된 언어 목록에 없으면 404로 리다이렉트
|
|
if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: "Language not supported"
|
|
});
|
|
}
|
|
});
|