From efd2b9051b7dde75a03ecbb88cb5c38e45106009 Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Wed, 3 Dec 2025 01:29:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=B7=A8=E8=B6=8A=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.production | 2 +- backend/app/services/horizons.py | 3 ++- frontend/src/utils/api.ts | 18 ++++++++++-------- nginx/nginx.conf | 5 +++++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.env.production b/.env.production index 82e9264..ee878f2 100644 --- a/.env.production +++ b/.env.production @@ -12,7 +12,7 @@ DATABASE_MAX_OVERFLOW=10 # ====================== # Redis Configuration # ====================== -REDIS_PASSWORD=cosmo +REDIS_PASSWORD= REDIS_MAX_CONNECTIONS=50 # ====================== diff --git a/backend/app/services/horizons.py b/backend/app/services/horizons.py index c9abca7..3ed3d6e 100644 --- a/backend/app/services/horizons.py +++ b/backend/app/services/horizons.py @@ -46,7 +46,8 @@ class HorizonsService: try: async with httpx.AsyncClient() as client: logger.info(f"Fetching raw data for body {body_id}") - response = await client.get(url, params=params, timeout=30.0) + # Reduced timeout for China network (NASA JPL may be blocked) + response = await client.get(url, params=params, timeout=5.0) if response.status_code != 200: raise Exception(f"NASA API returned status {response.status_code}") diff --git a/frontend/src/utils/api.ts b/frontend/src/utils/api.ts index e2cee08..0112a20 100644 --- a/frontend/src/utils/api.ts +++ b/frontend/src/utils/api.ts @@ -6,20 +6,22 @@ import type { CelestialDataResponse, BodyInfo } from '../types'; import { auth } from './auth'; // Dynamically determine the API base URL -// If VITE_API_BASE_URL is set, use it; otherwise use the current host with port 8000 const getApiBaseUrl = () => { if (import.meta.env.VITE_API_BASE_URL) { console.log('[API] Using VITE_API_BASE_URL:', import.meta.env.VITE_API_BASE_URL); return import.meta.env.VITE_API_BASE_URL; } - // Use the same host as the frontend, but with port 8000 - const protocol = window.location.protocol; - const hostname = window.location.hostname; - const apiUrl = `${protocol}//${hostname}:8000/api`; - console.log('[API] Constructed API URL:', apiUrl); - console.log('[API] Protocol:', protocol, 'Hostname:', hostname); - return apiUrl; + // In production, use relative path /api (proxied by Nginx) + // This works for both internal IP and external domain access + if (import.meta.env.PROD) { + console.log('[API] Using production relative path: /api'); + return '/api'; + } + + // In development, proxy is configured in vite.config.ts + console.log('[API] Using development relative path: /api'); + return '/api'; }; const API_BASE_URL = getApiBaseUrl(); diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 4ddc324..0b3fc5b 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -91,6 +91,11 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + # Add CORS headers for 3D models and textures + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept' always; + # Cache uploaded files expires 1y; add_header Cache-Control "public";