
- Set up FastAPI application with CORS and proper structure - Created User model with SQLAlchemy and SQLite database - Implemented JWT-based authentication with bcrypt password hashing - Added user registration, login, and profile endpoints - Created health check endpoint for monitoring - Set up Alembic for database migrations - Added comprehensive API documentation - Configured proper project structure with separate modules - Updated README with complete setup and usage instructions
38 lines
921 B
Python
38 lines
921 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.routers import auth, health
|
|
from app.db.session import engine
|
|
from app.db.base import Base
|
|
|
|
# Create tables
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title="User Authentication Service",
|
|
description="A FastAPI service for user authentication",
|
|
version="1.0.0",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
openapi_url="/openapi.json"
|
|
)
|
|
|
|
# CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(auth.router, prefix="/auth", tags=["authentication"])
|
|
app.include_router(health.router, tags=["health"])
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"title": "User Authentication Service",
|
|
"documentation": "/docs",
|
|
"health": "/health"
|
|
} |