From d53eff8287f89a736b9d46b2a324b125837d83c9 Mon Sep 17 00:00:00 2001 From: Nan Kyung Lee Date: Tue, 24 Mar 2026 15:59:33 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Google=20TTS=20CORS=20=EC=9A=B0=ED=9A=8C?= =?UTF-8?q?=20=E2=80=94=20Vite=20=ED=94=84=EB=A1=9D=EC=8B=9C=20/api/gtts?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/korea/OpsGuideModal.tsx | 2 +- frontend/vite.config.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/korea/OpsGuideModal.tsx b/frontend/src/components/korea/OpsGuideModal.tsx index 9625230..9e06004 100644 --- a/frontend/src/components/korea/OpsGuideModal.tsx +++ b/frontend/src/components/korea/OpsGuideModal.tsx @@ -150,7 +150,7 @@ export function OpsGuideModal({ ships, onClose, onFlyTo, onRouteSelect }: Props) if (audioRef.current) { audioRef.current.pause(); audioRef.current = null; } setSpeakingIdx(idx); const encoded = encodeURIComponent(text); - const url = `https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=zh-CN&q=${encoded}`; + const url = `/api/gtts?ie=UTF-8&client=tw-ob&tl=zh-CN&q=${encoded}`; const audio = new Audio(url); audioRef.current = audio; audio.onended = () => setSpeakingIdx(null); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index d81f6ba..1826b7d 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -115,6 +115,16 @@ export default defineConfig(({ mode }): UserConfig => ({ changeOrigin: true, rewrite: (path) => path.replace(/^\/ollama/, ''), }, + '/api/gtts': { + target: 'https://translate.google.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api\/gtts/, '/translate_tts'), + secure: true, + headers: { + 'Referer': 'https://translate.google.com/', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', + }, + }, }, }, }))