Jotzy/backend/app/main.py

41 lines
936 B
Python
Raw Permalink Normal View History

2026-01-06 16:47:18 +00:00
import os
2025-11-23 09:08:01 +00:00
from fastapi import FastAPI # type: ignore
from fastapi.middleware.cors import CORSMiddleware # type:ignore
2025-11-19 21:16:32 +00:00
2025-11-23 09:08:01 +00:00
from app.database import create_db_and_tables
from app.routes import auth, folders, notes, tags
2025-11-19 21:16:32 +00:00
2025-11-23 09:08:01 +00:00
app = FastAPI(title="Notes API")
2025-11-19 21:16:32 +00:00
cors_origins = os.getenv("CORS_ORIGINS", "http://localhost:5173").split(",")
2025-11-23 09:08:01 +00:00
app.add_middleware(
CORSMiddleware,
2026-01-06 16:47:18 +00:00
allow_origins=cors_origins,
2025-11-23 09:08:01 +00:00
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
2025-11-19 21:16:32 +00:00
2025-11-23 09:08:01 +00:00
@app.on_event("startup")
def on_startup():
create_db_and_tables()
2025-11-19 21:16:32 +00:00
2025-11-23 09:08:01 +00:00
app.include_router(notes.router, prefix="/api")
app.include_router(folders.router, prefix="/api")
app.include_router(auth.router, prefix="/api")
app.include_router(tags.router, prefix="/api")
2025-11-19 21:16:32 +00:00
2025-11-23 09:08:01 +00:00
@app.get("/")
def root():
return {"message": "Notes API"}
2026-01-06 16:47:18 +00:00
@app.get("/health")
def health():
"""Health check endpoint for Docker and Coolify"""
return {"status": "healthy"}