Spaces:
Running
Running
Update src/api/main.py
Browse files- src/api/main.py +25 -8
src/api/main.py
CHANGED
|
@@ -1,22 +1,31 @@
|
|
| 1 |
from contextlib import asynccontextmanager
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
from src.api.notes_routes import router as notes_router
|
| 6 |
from src.api.auth_routes import router as auth_router
|
| 7 |
-
#
|
| 8 |
|
| 9 |
@asynccontextmanager
|
| 10 |
async def lifespan(app: FastAPI):
|
| 11 |
-
|
|
|
|
| 12 |
pot_server.start()
|
| 13 |
yield
|
| 14 |
-
|
|
|
|
| 15 |
pot_server.stop()
|
| 16 |
|
| 17 |
-
app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
# تفعيل الـ CORS عشان الـ Flutter Web يشتغل
|
| 20 |
app.add_middleware(
|
| 21 |
CORSMiddleware,
|
| 22 |
allow_origins=["*"],
|
|
@@ -25,10 +34,18 @@ app.add_middleware(
|
|
| 25 |
allow_headers=["*"],
|
| 26 |
)
|
| 27 |
|
| 28 |
-
# تسجيل المسارات (
|
| 29 |
app.include_router(notes_router)
|
| 30 |
app.include_router(auth_router)
|
| 31 |
|
| 32 |
@app.get("/")
|
| 33 |
def read_root():
|
| 34 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from contextlib import asynccontextmanager
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
|
| 5 |
+
# استدعاء المدير (POT Server) والـ Routers
|
| 6 |
+
from src.api.pot_server import pot_server
|
| 7 |
from src.api.notes_routes import router as notes_router
|
| 8 |
from src.api.auth_routes import router as auth_router
|
| 9 |
+
# لو عندك ملفات تانية زي analytics_routes استوردها هنا بنفس الطريقة
|
| 10 |
|
| 11 |
@asynccontextmanager
|
| 12 |
async def lifespan(app: FastAPI):
|
| 13 |
+
# الجزء ده بيتنفذ أول ما السيرفر يفتح
|
| 14 |
+
print("🚀 Lifespan: Starting POT solver server (bgutil v1.3.1)...")
|
| 15 |
pot_server.start()
|
| 16 |
yield
|
| 17 |
+
# الجزء ده بيتنفذ لما السيرفر يقفل
|
| 18 |
+
print("🛑 Lifespan: Stopping POT solver server...")
|
| 19 |
pot_server.stop()
|
| 20 |
|
| 21 |
+
# تعريف الـ app مع إضافة الـ lifespan والاسم الاحترافي لمشروع تخرجك
|
| 22 |
+
app = FastAPI(
|
| 23 |
+
title="AIdea API",
|
| 24 |
+
description="YouTube Study Notes Generation Engine",
|
| 25 |
+
lifespan=lifespan
|
| 26 |
+
)
|
| 27 |
|
| 28 |
+
# تفعيل الـ CORS عشان الـ Flutter Web والـ Mobile يشتغلوا بدون مشاكل
|
| 29 |
app.add_middleware(
|
| 30 |
CORSMiddleware,
|
| 31 |
allow_origins=["*"],
|
|
|
|
| 34 |
allow_headers=["*"],
|
| 35 |
)
|
| 36 |
|
| 37 |
+
# تسجيل المسارات (الخطوة دي هي اللي بتخلي الـ 404 تختفي)
|
| 38 |
app.include_router(notes_router)
|
| 39 |
app.include_router(auth_router)
|
| 40 |
|
| 41 |
@app.get("/")
|
| 42 |
def read_root():
|
| 43 |
+
return {
|
| 44 |
+
"status": "online",
|
| 45 |
+
"message": "Welcome to AIdea API! Everything is working perfectly.",
|
| 46 |
+
"pot_server": "running"
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
@app.get("/health")
|
| 50 |
+
def health_check():
|
| 51 |
+
return {"status": "healthy", "pot_running": pot_server.is_running()}
|