File size: 1,069 Bytes
8393a26 |
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 |
from fastapi import FastAPI
from starlette.middleware.sessions import SessionMiddleware
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates
from app.core.config import settings
from app.api.v1.api import api_router
app = FastAPI(title=settings.PROJECT_NAME)
# 1. Add Session Middleware
# This is required for Authlib to store the temporary state during the OAuth dance
app.add_middleware(
SessionMiddleware,
secret_key=settings.SECRET_KEY,
https_only=False # Set to True in production with SSL
)
# 2. Include API Routers
app.include_router(api_router)
# 3. Simple Frontend for demonstration
templates = Jinja2Templates(directory="app/templates")
@app.get("/", response_class=HTMLResponse)
async def root(request: Request):
user = request.session.get("user")
return templates.TemplateResponse("index.html", {"request": request, "user": user})
if __name__ == "__main__":
import uvicorn
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True) |