Spaces:
Sleeping
Sleeping
| import axios from 'axios' | |
| import { ref } from 'vue' | |
| // === API 後端位置設定 === | |
| // 🌐 【HF 部署模式】指向 Hugging Face Space 後端。透過直接請求後端網域,避免使用 Nginx 代理轉發導致的 Hugging Face Ingress 429 (Too Many Requests) 限制,且後端已配置 CORS allow_origins=["*"]。 | |
| // 💻 【本地開發模式】若在本地端(localhost:5173)則自動指向本地後端(localhost:7860) | |
| const API_BASE_URL = window.location.origin === 'http://localhost:5173' | |
| ? 'http://localhost:7860' | |
| : 'https://my-project-team-infosecai-finalproj.hf.space'; | |
| export const showPendingVerifyAlert = ref(false) | |
| export const showBlockedModal = ref(false) | |
| export const pendingVerifyMessage = ref('') | |
| export const blockedMessage = ref('') | |
| const api = axios.create({ | |
| baseURL: API_BASE_URL, | |
| headers: { | |
| 'Content-Type': 'application/json' | |
| } | |
| }) | |
| api.interceptors.response.use( | |
| (response) => { | |
| const data = response.data | |
| if (data && data.status === 'pending_verify') { | |
| showPendingVerifyAlert.value = true | |
| pendingVerifyMessage.value = data.message || '偵測到異常,請於5分鐘內確認 Email 以繼續使用' | |
| } else if (data && data.status === 'blocked') { | |
| showBlockedModal.value = true | |
| blockedMessage.value = '驗證逾時或帳號遭非法存取,已強制登出' | |
| } | |
| return response | |
| }, | |
| (error) => { | |
| return Promise.reject(error) | |
| } | |
| ) | |
| export default api | |