-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_server.py
More file actions
63 lines (53 loc) · 1.73 KB
/
run_server.py
File metadata and controls
63 lines (53 loc) · 1.73 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
#!/usr/bin/env python
"""
Production startup script for the Permit API.
Optimized for AWS App Runner and other cloud platforms.
"""
import os
import sys
def setup_environment():
"""Setup environment and paths."""
# Add the project root to Python path
try:
project_root = os.path.dirname(os.path.abspath(__file__))
except NameError:
# Handle case when __file__ is not defined (exec context)
project_root = os.getcwd()
sys.path.insert(0, project_root)
# Create necessary directories
os.makedirs('data/eea/renewable-energy', exist_ok=True)
os.makedirs('data/eea/pollution', exist_ok=True)
os.makedirs('logs', exist_ok=True)
os.makedirs('reference', exist_ok=True)
return project_root
def main():
"""Main application entry point."""
project_root = setup_environment()
# Import after path setup
from app.api_server import app
# Configure for production/cloud deployment
port = int(os.environ.get('PORT', 5000))
debug = os.environ.get('FLASK_DEBUG', '0') == '1'
env = os.environ.get('FLASK_ENV', 'development')
host = '0.0.0.0'
print(f"🚀 Starting Permit API")
print(f" Port: {port}")
print(f" Environment: {env}")
print(f" Debug mode: {debug}")
print(f" Project root: {project_root}")
print(f" Host: {host}")
# Run the FastAPI app with uvicorn
try:
import uvicorn
uvicorn.run(
"app.api_server:app",
host=host,
port=port,
reload=debug,
log_level="info" if not debug else "debug"
)
except Exception as e:
print(f"❌ Failed to start server: {e}")
sys.exit(1)
if __name__ == '__main__':
main()