First commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
import crud
|
||||
from database import engine
|
||||
from models import Base
|
||||
from create_admin import create_admin
|
||||
from os import getenv
|
||||
|
||||
# Crear tablas
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI(title="User Management API", version="1.0.0")
|
||||
|
||||
# Configurar CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[getenv("FRONT_END_URL")],
|
||||
allow_credentials=True,
|
||||
allow_methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
|
||||
allow_headers=["Authorization", "Content-Type"],
|
||||
)
|
||||
|
||||
# Incluir rutas
|
||||
app.include_router(crud.router, prefix="/api/v1", tags=["api"])
|
||||
|
||||
@app.get("/")
|
||||
def root():
|
||||
return {"message": "User Management API"}
|
||||
|
||||
@app.get("/health")
|
||||
def health_check():
|
||||
return {"status": "healthy"}
|
||||
|
||||
##Eliminar en producción
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""Ejecutar scraper síncrono en thread separado"""
|
||||
# Usar asyncio.to_thread para ejecutar código síncrono
|
||||
create_admin()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
Reference in New Issue
Block a user