Update main.py
Browse files
main.py
CHANGED
@@ -1,26 +1,30 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
3 |
-
from core.database import engine
|
4 |
-
from core.models.appointment import Appointment
|
5 |
-
from core.models.user import User
|
6 |
-
from routes import appointments, users
|
7 |
-
|
8 |
-
# Create FastAPI app first
|
9 |
-
app = FastAPI()
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
#
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
from core.database import engine
|
4 |
+
from core.models.appointment import Appointment
|
5 |
+
from core.models.user import User
|
6 |
+
from routes import appointments, users
|
7 |
+
|
8 |
+
# Create FastAPI app first
|
9 |
+
app = FastAPI()
|
10 |
+
|
11 |
+
@app.get("/")
|
12 |
+
def health_check():
|
13 |
+
return {"message": "π API is up and running!"}
|
14 |
+
|
15 |
+
# β
Enable CORS BEFORE including any routers
|
16 |
+
app.add_middleware(
|
17 |
+
CORSMiddleware,
|
18 |
+
allow_origins=["http://localhost:3000"], # React frontend
|
19 |
+
allow_credentials=True,
|
20 |
+
allow_methods=["*"],
|
21 |
+
allow_headers=["*"],
|
22 |
+
)
|
23 |
+
|
24 |
+
# Create tables
|
25 |
+
Appointment.__table__.create(bind=engine, checkfirst=True)
|
26 |
+
User.__table__.create(bind=engine, checkfirst=True)
|
27 |
+
|
28 |
+
# Register routers
|
29 |
+
app.include_router(appointments.router)
|
30 |
+
app.include_router(users.router)
|