1- from os import getenv
2-
3- from fastapi import FastAPI
4- from fastapi .middleware .cors import CORSMiddleware
5- from sqlalchemy import create_engine
6- from sqlalchemy .ext .declarative import declarative_base
7- from sqlalchemy .orm import sessionmaker
8- from dotenv import load_dotenv
9-
10- from app .core .middleware import LoggingAndPerformanceMiddleware
11-
12- load_dotenv ()
13-
14- DATABASE_URL = getenv ("DATABASE_URL" )
15- if not DATABASE_URL :
16- raise ValueError ("DATABASE_URL is not set in environment variables." )
17-
18- engine = create_engine (DATABASE_URL )
19- SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = engine )
20- Base = declarative_base ()
21-
22- Base .metadata .create_all (bind = engine )
23- print ("✅ Tables created successfully." )
24-
25-
26- def get_db ():
27- db = SessionLocal ()
28- try :
29- yield db
30- finally :
31- db .close ()
32-
33-
34- def create_app ():
35- app = FastAPI ()
36-
37- app .add_middleware (LoggingAndPerformanceMiddleware )
38- app .add_middleware (
39- CORSMiddleware ,
40- allow_origins = [
41- "http://localhost:3000" ,
42- "https://job-fit-ai.vercel.app"
43- ],
44- allow_credentials = True ,
45- allow_methods = ["*" ],
46- allow_headers = ["*" ],
47- )
48-
49- Base .metadata .create_all (bind = engine )
50-
51- from app .routes .auth import router as auth_router
52- from app .routes .cheatsheet import router as cheatsheet_router
53- from app .routes .user import router as user_router
54- from app .routes .health import router as health_router
55-
56- app .include_router (auth_router , prefix = "/auth" )
57- app .include_router (cheatsheet_router , prefix = "/cheatsheet" )
58- app .include_router (user_router , prefix = "/user" )
59- app .include_router (health_router , prefix = "/health" )
60-
61- return app
0 commit comments