Repository navigation
Expand file tree
/
Copy pathstart_server.py
More file actions
85 lines (74 loc) · 2.19 KB
/
Copy pathstart_server.py
File metadata and controls
85 lines (74 loc) · 2.19 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
"""
Startup script for the Acharya Job Portal
"""
import os
import sys
import secrets
import subprocess
import time
from pathlib import Path
def check_requirements():
"""Check if all required packages are installed"""
try:
import fastapi
import uvicorn
import motor
import jose
import bcrypt
import dotenv
print("✅ All required packages are installed")
return True
except ImportError as e:
print(f"❌ Missing required package: {e}")
print("Installing requirements...")
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
return True
def create_env_file():
"""Create .env file if it doesn't exist"""
env_file = Path(".env")
if not env_file.exists():
env_content = f"""# MongoDB Configuration
MONGODB_URL=mongodb://localhost:27017/acharya
# JWT Configuration
JWT_SECRET_KEY={secrets.token_hex(32)}
# Server Configuration
HOST=0.0.0.0
PORT=8000
"""
with open(env_file, "w") as f:
f.write(env_content)
print("✅ Created .env file with default configuration")
else:
print("✅ .env file already exists")
def start_server():
"""Start the FastAPI server"""
print("🚀 Starting Acharya Job Portal Server...")
print("📍 Server will be available at: http://localhost:8000")
print("📍 API Documentation: http://localhost:8000/docs")
print("📍 Frontend: http://localhost:8000/static/index.html")
print("\n" + "="*50)
try:
subprocess.run([
sys.executable, "-m", "uvicorn",
"main:app",
"--host", "0.0.0.0",
"--port", "8000",
"--reload"
])
except KeyboardInterrupt:
print("\n🛑 Server stopped by user")
except Exception as e:
print(f"❌ Error starting server: {e}")
def main():
print("🎯 Acharya Job Portal - Career Forging Platform")
print("="*50)
# Check and install requirements
if not check_requirements():
return
# Create .env file
create_env_file()
# Start server
start_server()
if __name__ == "__main__":
main()