File size: 835 Bytes
5e37a6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app import models
from app.database import engine
from app.routers import auth, teacher, student

# Create all database tables
models.Base.metadata.create_all(bind=engine)

app = FastAPI()

# CORS Middleware Setup
# Replace "http://localhost:3000" with your Next.js frontend URL
origins = [
    "http://localhost:3000",
    "http://127.0.0.1:63442",
    "http://localhost:9002",
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Include Routers
app.include_router(auth.router)
app.include_router(teacher.router)
app.include_router(student.router)

@app.get("/")
def read_root():
    return {"message": "Welcome to the Smart Attendance System API"}