ALI7ADEL commited on
Commit
40dbb61
·
verified ·
1 Parent(s): 81618af

Update src/api/main.py

Browse files
Files changed (1) hide show
  1. 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
- from src.api.pot_server import pot_server
 
 
5
  from src.api.notes_routes import router as notes_router
6
  from src.api.auth_routes import router as auth_router
7
- # استورد أي routers تانية عندك هنا
8
 
9
  @asynccontextmanager
10
  async def lifespan(app: FastAPI):
11
- print("🚀 Starting POT solver server...")
 
12
  pot_server.start()
13
  yield
14
- print("🛑 Stopping POT solver server...")
 
15
  pot_server.stop()
16
 
17
- app = FastAPI(title="AIdea API", lifespan=lifespan)
 
 
 
 
 
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
- # تسجيل المسارات (مهم جداً عشان الـ 404 تختفي)
29
  app.include_router(notes_router)
30
  app.include_router(auth_router)
31
 
32
  @app.get("/")
33
  def read_root():
34
- return {"message": "AIdea API is Live and POT is working!"}
 
 
 
 
 
 
 
 
 
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()}