解决跨越问题

main
mula.liu 2025-12-03 01:29:44 +08:00
parent f4b0cdc569
commit efd2b9051b
4 changed files with 18 additions and 10 deletions

View File

@ -12,7 +12,7 @@ DATABASE_MAX_OVERFLOW=10
# ====================== # ======================
# Redis Configuration # Redis Configuration
# ====================== # ======================
REDIS_PASSWORD=cosmo REDIS_PASSWORD=
REDIS_MAX_CONNECTIONS=50 REDIS_MAX_CONNECTIONS=50
# ====================== # ======================

View File

@ -46,7 +46,8 @@ class HorizonsService:
try: try:
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
logger.info(f"Fetching raw data for body {body_id}") 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: if response.status_code != 200:
raise Exception(f"NASA API returned status {response.status_code}") raise Exception(f"NASA API returned status {response.status_code}")

View File

@ -6,20 +6,22 @@ import type { CelestialDataResponse, BodyInfo } from '../types';
import { auth } from './auth'; import { auth } from './auth';
// Dynamically determine the API base URL // 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 = () => { const getApiBaseUrl = () => {
if (import.meta.env.VITE_API_BASE_URL) { if (import.meta.env.VITE_API_BASE_URL) {
console.log('[API] Using VITE_API_BASE_URL:', 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; return import.meta.env.VITE_API_BASE_URL;
} }
// Use the same host as the frontend, but with port 8000 // In production, use relative path /api (proxied by Nginx)
const protocol = window.location.protocol; // This works for both internal IP and external domain access
const hostname = window.location.hostname; if (import.meta.env.PROD) {
const apiUrl = `${protocol}//${hostname}:8000/api`; console.log('[API] Using production relative path: /api');
console.log('[API] Constructed API URL:', apiUrl); return '/api';
console.log('[API] Protocol:', protocol, 'Hostname:', hostname); }
return apiUrl;
// In development, proxy is configured in vite.config.ts
console.log('[API] Using development relative path: /api');
return '/api';
}; };
const API_BASE_URL = getApiBaseUrl(); const API_BASE_URL = getApiBaseUrl();

View File

@ -91,6 +91,11 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; 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 # Cache uploaded files
expires 1y; expires 1y;
add_header Cache-Control "public"; add_header Cache-Control "public";