42 lines
978 B
Python
42 lines
978 B
Python
import logging
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.routes import api_router
|
|
from app.core.config import settings
|
|
from app.db.session import get_db
|
|
from app.db.init_db import init_db
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
description="Task Manager API allows users to create, manage and track tasks",
|
|
version="0.1.0",
|
|
openapi_url="/openapi.json",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
)
|
|
|
|
# Set all CORS enabled origins
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(api_router)
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def startup_db_client():
|
|
"""Initialize the database on startup."""
|
|
db = next(get_db())
|
|
init_db(db)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |