From b45d119d782fbc26cfa10c475917093791ca0334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=84=AD=E6=B2=9B=E8=BB=92?= Date: Sun, 5 Oct 2025 20:47:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20generate=20?= =?UTF-8?q?=E9=A0=81=E9=9D=A2=E7=A1=AC=E7=B7=A8=E7=A2=BC=20API=20URL=20?= =?UTF-8?q?=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 🔧 修正 app/generate/page.tsx 中的硬編碼端口 - 🔧 修正 useSentenceAnalysis.ts Hook 中的硬編碼端口 - ✅ 統一使用 API_CONFIG.BASE_URL 配置 - ✅ 修正 "Failed to fetch" 錯誤 - ⚙️ 確保 AI 句子分析功能正常運作 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- frontend/app/generate/page.tsx | 3 ++- frontend/hooks/generate/useSentenceAnalysis.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/app/generate/page.tsx b/frontend/app/generate/page.tsx index f2689b2..5450004 100644 --- a/frontend/app/generate/page.tsx +++ b/frontend/app/generate/page.tsx @@ -8,6 +8,7 @@ import { useToast } from '@/components/shared/Toast' import { flashcardsService } from '@/lib/services/flashcards' import { compareCEFRLevels, getLevelIndex, getTargetLearningRange } from '@/lib/utils/cefrUtils' import { BluePlayButton } from '@/components/shared/BluePlayButton' +import { API_CONFIG } from '@/lib/config/api' import Link from 'next/link' // 常數定義 @@ -51,7 +52,7 @@ function GenerateContent() { setIsAnalyzing(true) try { - const response = await fetch('http://localhost:5008/api/ai/analyze-sentence', { + const response = await fetch(`${API_CONFIG.BASE_URL}/api/ai/analyze-sentence`, { method: 'POST', headers: { 'Content-Type': 'application/json' diff --git a/frontend/hooks/generate/useSentenceAnalysis.ts b/frontend/hooks/generate/useSentenceAnalysis.ts index 8d21bef..6bf967f 100644 --- a/frontend/hooks/generate/useSentenceAnalysis.ts +++ b/frontend/hooks/generate/useSentenceAnalysis.ts @@ -1,6 +1,7 @@ import { useState } from 'react' import { useToast } from '@/components/shared/Toast' import { getLevelIndex } from '@/lib/utils/cefrUtils' +import { API_CONFIG } from '@/lib/config/api' interface AnalysisResult { originalText: string @@ -19,7 +20,7 @@ export function useSentenceAnalysis() { setIsAnalyzing(true) try { - const response = await fetch('http://localhost:5008/api/ai/analyze-sentence', { + const response = await fetch(`${API_CONFIG.BASE_URL}/api/ai/analyze-sentence`, { method: 'POST', headers: { 'Content-Type': 'application/json'