init
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
from app.routes import script, chat, game, character, clue
|
||||
from app.models.database import init_db
|
||||
from app.models import orm
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
hermes_api_url: str = "http://localhost:11434/v1"
|
||||
hermes_model: str = "hermes-3"
|
||||
database_url: str = "postgresql+asyncpg://hermes:hermes123@localhost:5432/hermes_live"
|
||||
secret_key: str = "change-me-in-production"
|
||||
cors_origins: str = "http://localhost:3000,http://localhost:5173"
|
||||
log_level: str = "INFO"
|
||||
|
||||
model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
||||
app = FastAPI(title="Hermes Live Show", version="0.1.0")
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.cors_origins.split(","),
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(script.router, prefix="/api/scripts", tags=["scripts"])
|
||||
app.include_router(chat.router, prefix="/api", tags=["messages"])
|
||||
app.include_router(game.router, prefix="/api/game", tags=["game"])
|
||||
app.include_router(character.router, prefix="/api/characters", tags=["characters"])
|
||||
app.include_router(clue.router, prefix="/api", tags=["clues"])
|
||||
|
||||
from app.sockets.handlers import create_socket_app
|
||||
socket_app = create_socket_app(app)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
await init_db(settings.database_url)
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
def health_check():
|
||||
return {"status": "ok", "version": "0.1.0"}
|
||||
Reference in New Issue
Block a user