feat(phase-1): Complete foundation setup
- Add User model and authentication system with JWT cookies - Implement login/logout routes and protected dashboard - Add Alembic database migration configuration - Add create_admin.py script for initial user setup - Make ContentGenerator and ImageGenerator lazy-initialized - Add comprehensive API keys setup documentation - Fix startup errors when services unavailable Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
18
app/main.py
18
app/main.py
@@ -5,17 +5,27 @@ Sistema automatizado para la creación y publicación de contenido
|
||||
en redes sociales (X, Threads, Instagram, Facebook).
|
||||
"""
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.api.routes import posts, products, services, calendar, dashboard, interactions
|
||||
from app.api.routes import posts, products, services, calendar, dashboard, interactions, auth
|
||||
from app.core.config import settings
|
||||
from app.core.database import engine
|
||||
from app.models import Base
|
||||
|
||||
# Crear tablas en la base de datos
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Lifecycle manager - crea tablas al iniciar si hay conexión a BD."""
|
||||
try:
|
||||
Base.metadata.create_all(bind=engine)
|
||||
except Exception as e:
|
||||
print(f"⚠️ No se pudo conectar a BD: {e}")
|
||||
print(" La app funcionará pero sin persistencia hasta configurar BD")
|
||||
yield
|
||||
|
||||
# Inicializar aplicación FastAPI
|
||||
app = FastAPI(
|
||||
@@ -24,6 +34,7 @@ app = FastAPI(
|
||||
version="1.0.0",
|
||||
docs_url="/api/docs",
|
||||
redoc_url="/api/redoc",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
# Configurar CORS
|
||||
@@ -39,6 +50,7 @@ app.add_middleware(
|
||||
app.mount("/static", StaticFiles(directory="dashboard/static"), name="static")
|
||||
|
||||
# Registrar rutas
|
||||
app.include_router(auth.router, prefix="", tags=["Auth"])
|
||||
app.include_router(dashboard.router, prefix="", tags=["Dashboard"])
|
||||
app.include_router(posts.router, prefix="/api/posts", tags=["Posts"])
|
||||
app.include_router(products.router, prefix="/api/products", tags=["Products"])
|
||||
|
||||
Reference in New Issue
Block a user