This commit is contained in:
admin
2026-01-22 22:37:02 +09:00
parent 50e534094d
commit 1868591704
4 changed files with 28 additions and 9 deletions

View File

@@ -2,7 +2,7 @@ from dotenv import load_dotenv
load_dotenv()
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.responses import JSONResponse, RedirectResponse
from pydantic import ValidationError
from fastapi.middleware.cors import CORSMiddleware
@@ -32,9 +32,9 @@ async def validation_exception_handler(request: Request, exc: ValidationError):
# ─────────────────────────
# ルート(稼働確認)
# ─────────────────────────
@app.get("/", include_in_schema=False)
def root():
return RedirectResponse(url="/index.html")
#@app.get("/", include_in_schema=False)
#def root():
# return RedirectResponse(url="/index.html")
# ─────────────────────────
# ルーター登録(※ 必ず app 定義の後)
@@ -124,10 +124,18 @@ app.mount(
# )
# フロントエンドファイル配信
frontend_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "frontend")
if os.path.exists(frontend_path):
from fastapi.staticfiles import StaticFiles
from pathlib import Path
# フロントエンド配信(/app/frontend
BASE_DIR = Path(__file__).resolve().parent.parent # /app
frontend_path = BASE_DIR / "frontend"
print("Frontend path =", frontend_path)
if frontend_path.exists():
app.mount(
"/frontend",
"/",
StaticFiles(directory=frontend_path, html=True),
name="frontend",
)