feat(api): backend wystawia wyłącznie API i steruje botem
Panel działa w osobnym kontenerze, więc serwis Pythona przestaje serwować pliki statyczne: - usunięty mount StaticFiles na "/" wraz z importem - tytuł aplikacji zmieniony na "ŻyrarBOT API" - GET / zwraca opis usługi zamiast panelu, żeby wejście pod adres backendu nie kończyło się nic niemówiącym 404 - GET /api/health informuje, czy bot zdążył połączyć się z Discordem; przydaje się jako healthcheck kontenera i przy diagnozie proxy Pozostałe endpointy oraz WebSocket pozostają bez zmian. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d3408da2ed
commit
8d32d5afc6
1 file changed
+17
-6
@@ -1,5 +1,4 @@
|
||||
from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect, UploadFile, File
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Optional
|
||||
import asyncio
|
||||
@@ -11,8 +10,9 @@ import shutil
|
||||
from bot import bot
|
||||
from ytdl import YTDLSource
|
||||
|
||||
# Initialize FastAPI application
|
||||
app = FastAPI(title="ŻyrarBOT Queue Controller")
|
||||
# Initialize FastAPI application.
|
||||
# The service exposes the API only - the web panel is a separate container.
|
||||
app = FastAPI(title="ŻyrarBOT API")
|
||||
|
||||
# FastAPI Request Models
|
||||
class PlayRequest(BaseModel):
|
||||
@@ -82,6 +82,20 @@ def get_active_guild():
|
||||
return None
|
||||
|
||||
# FastAPI Endpoints
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""Service descriptor - the panel is served by its own container."""
|
||||
return {
|
||||
"service": "zyrarbot-api",
|
||||
"docs": "/docs",
|
||||
"status": "/api/status",
|
||||
"websocket": "/ws",
|
||||
}
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health():
|
||||
return {"status": "ok", "discord_ready": bot.is_ready()}
|
||||
|
||||
@app.get("/api/status")
|
||||
async def get_status():
|
||||
music_cog = bot.get_cog("MusicBot")
|
||||
@@ -740,6 +754,3 @@ async def startup_event():
|
||||
asyncio.create_task(wait_and_register_callback())
|
||||
|
||||
asyncio.create_task(status_broadcast_loop())
|
||||
|
||||
# Serve UI Files (Must be registered after API routes)
|
||||
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
||||
Reference in new issue
Block a user