
- Set up project structure with FastAPI application - Implement SQLAlchemy models for users, services, projects, team members, contacts - Create API endpoints for website functionality - Implement JWT authentication system with user roles - Add file upload functionality for media - Configure CORS and health check endpoints - Add database migrations with Alembic - Create comprehensive README with setup instructions
78 lines
1.8 KiB
Python
78 lines
1.8 KiB
Python
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.openapi.utils import get_openapi
|
|
|
|
from app.api.v1.api import api_router
|
|
from app.core.config import settings
|
|
from app.utils.init_db import init_db
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
description=settings.PROJECT_DESCRIPTION,
|
|
version=settings.VERSION,
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
openapi_url="/openapi.json",
|
|
)
|
|
|
|
# Set all CORS enabled origins
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(api_router, prefix=settings.API_V1_STR)
|
|
|
|
|
|
@app.get("/", tags=["Root"])
|
|
async def root():
|
|
"""
|
|
Root endpoint returning basic information about the API.
|
|
"""
|
|
return {
|
|
"title": settings.PROJECT_NAME,
|
|
"description": settings.PROJECT_DESCRIPTION,
|
|
"version": settings.VERSION,
|
|
"docs_url": "/docs",
|
|
"health_check": "/health"
|
|
}
|
|
|
|
|
|
@app.get("/health", tags=["Health"])
|
|
async def health_check():
|
|
"""
|
|
Health check endpoint to verify service status.
|
|
"""
|
|
return {"status": "healthy"}
|
|
|
|
|
|
def custom_openapi():
|
|
if app.openapi_schema:
|
|
return app.openapi_schema
|
|
openapi_schema = get_openapi(
|
|
title=settings.PROJECT_NAME,
|
|
version=settings.VERSION,
|
|
description=settings.PROJECT_DESCRIPTION,
|
|
routes=app.routes,
|
|
)
|
|
app.openapi_schema = openapi_schema
|
|
return app.openapi_schema
|
|
|
|
|
|
app.openapi = custom_openapi
|
|
|
|
|
|
@app.on_event("startup")
|
|
def startup_event():
|
|
"""
|
|
Initialize the database with initial data on startup.
|
|
"""
|
|
init_db()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |