Initial commit with authentication and routes for registering/login already set up
This commit is contained in:
29
app/main.py
Normal file
29
app/main.py
Normal file
@ -0,0 +1,29 @@
|
||||
from fastapi import FastAPI
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
from contextlib import asynccontextmanager
|
||||
from app.routers import auth # Assuming you have a router for auth logic
|
||||
from app.database import engine
|
||||
from app.models import Base
|
||||
|
||||
# Define a lifespan context manager to handle startup and shutdown events
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Run code before the app starts
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
# Yield control to run the app
|
||||
yield
|
||||
|
||||
# Run code before the app shuts down (if needed)
|
||||
await engine.dispose()
|
||||
|
||||
# Initialize the FastAPI app with the lifespan event handler
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
# Register your API routes
|
||||
app.include_router(auth.router)
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Hello World"}
|
||||
Reference in New Issue
Block a user