-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathweb_server.py
More file actions
65 lines (52 loc) · 2.03 KB
/
web_server.py
File metadata and controls
65 lines (52 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
MeetSpot Local Development Server
=================================
This is the main entry point for local development.
It imports and runs the FastAPI application from api/index.py.
For production deployment on Railway, this file serves as the main entry point.
"""
import sys
import os
# Add the project root to Python path
sys.path.insert(0, os.path.dirname(__file__))
# Load environment variables from .env file
from dotenv import load_dotenv
load_dotenv()
def main():
"""Main entry point for development and production server"""
try:
# Import the FastAPI app from api/index.py
from api.index import app
import uvicorn
# Get port from environment variable (Railway sets PORT automatically)
port = int(os.environ.get("PORT", 8000))
# Detect if running in production (Railway sets RAILWAY_ENVIRONMENT)
is_production = os.environ.get("RAILWAY_ENVIRONMENT") is not None
if is_production:
print("🚀 启动 MeetSpot 生产服务器 (Railway)...")
print(f"📍 服务端口: {port}")
else:
print("🚀 启动 MeetSpot 本地开发服务器...")
print(f"📍 服务地址: http://localhost:{port}")
print("📚 API文档: /docs")
print("🔧 健康检查: /health")
print("=" * 50)
# Run the server with production-optimized settings
uvicorn.run(
"api.index:app",
host="0.0.0.0",
port=port,
reload=not is_production, # Disable reload in production
log_level="info",
access_log=True
)
except ImportError as e:
print(f"❌ 导入错误: {e}")
print("请确保已安装所有依赖: pip install -r requirements.txt")
sys.exit(1)
except Exception as e:
print(f"❌ 启动失败: {e}")
sys.exit(1)
if __name__ == "__main__":
main()