-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
85 lines (71 loc) · 2.32 KB
/
start.py
File metadata and controls
85 lines (71 loc) · 2.32 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""
Production startup script for Envoyou CEVS API
Optimized for Render deployment
"""
import os
import sys
import uvicorn
from pathlib import Path
def setup_production_environment():
"""Setup environment for production deployment"""
# Ensure logs directory exists
logs_dir = Path("logs")
logs_dir.mkdir(exist_ok=True)
# Set production defaults if not set
env_defaults = {
"PORT": "10000",
"LOG_LEVEL": "INFO",
"ENVIRONMENT": "production",
"DEBUG": "false",
"CORS_ORIGINS": "https://envoyou.com,https://your-frontend-domain.com",
}
for key, default_value in env_defaults.items():
if not os.getenv(key):
os.environ[key] = default_value
print(f"Set {key}={default_value}")
# Ensure critical paths exist
reference_files = [
"reference/EDGAR_emiss_on_UCDB_2024.xlsx",
"reference/list_iso.xlsx",
"reference/Annex III_Best practices and justifications.xlsx"
]
for file_path in reference_files:
if not Path(file_path).exists():
print(f"Warning: {file_path} not found")
print("✅ Production environment setup complete")
def main():
"""Main startup function"""
print("🚀 Starting Envoyou CEVS API - Production Mode")
print("=" * 50)
# Setup environment
setup_production_environment()
# Get port from environment
port = int(os.getenv("PORT", "10000"))
host = os.getenv("HOST", "0.0.0.0")
workers = int(os.getenv("WEB_CONCURRENCY", "1"))
log_level = os.getenv("LOG_LEVEL", "info").lower()
print(f"📡 Server Configuration:")
print(f" Host: {host}")
print(f" Port: {port}")
print(f" Workers: {workers}")
print(f" Log Level: {log_level}")
print(f" Environment: {os.getenv('ENVIRONMENT', 'unknown')}")
print()
# Start server
try:
uvicorn.run(
"app.api_server:app",
host=host,
port=port,
workers=workers,
log_level=log_level,
access_log=True,
server_header=False, # Don't expose server info
date_header=False, # Don't expose date for caching
)
except Exception as e:
print(f"❌ Failed to start server: {e}")
sys.exit(1)
if __name__ == "__main__":
main()