-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (63 loc) · 2.16 KB
/
Copy pathmain.py
File metadata and controls
83 lines (63 loc) · 2.16 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
from fastapi import FastAPI
import uvicorn
import asyncio
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
from dotenv import load_dotenv
from db.mongo import get_mongo_client
from db.indexes import create_indexes
from routers.auth import auth_router
from routers.event import event_router
from routers.registrations import registrations_router
from core.logging.middleware import RequestLoggingMiddleware
from core.logging.trace import TraceIDMiddleware
from core.logging.transport import api_log_worker, audit_log_worker
from core.security.apiKeyMiddleware import ApiKeyMiddleware
load_dotenv()
openAPI_tags = [
{"name": "Authentication", "description": "User authentication and authorization."},
{"name": "Events", "description": "Event creation, updates, and metadata."},
{"name": "Registrations", "description": "User registrations and participation in events."},
{"name": "Attendance", "description": "Attendance tracking and analytics."},
]
@asynccontextmanager
async def lifespan(app: FastAPI):
await create_indexes()
asyncio.create_task(api_log_worker())
asyncio.create_task(audit_log_worker())
print("✅ Logging workers started")
yield
client = get_mongo_client()
await client.close()
print("🛑 MongoDB connection closed")
app = FastAPI(
title="Core Platform API",
description="Core Platform API is the centralized backend service powering AWS Cloud Club LPU platforms.",
version="1.0.0",
redoc_url="/docs/v2",
openapi_tags=openAPI_tags,
lifespan=lifespan,
)
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:3000",
"https://awslpu.in",
"https://www.awslpu.in"
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(RequestLoggingMiddleware)
app.add_middleware(TraceIDMiddleware)
app.add_middleware(ApiKeyMiddleware)
registered_routers = [
auth_router,
event_router,
registrations_router,
]
for router in registered_routers:
app.include_router(router)
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=5000, reload=True)