diff --git a/backend/app/main.py b/backend/app/main.py index afe990b..3985786 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -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", ) diff --git a/backend/app/payroll/settings/router.py b/backend/app/payroll/settings/router.py index e223395..51819a7 100644 --- a/backend/app/payroll/settings/router.py +++ b/backend/app/payroll/settings/router.py @@ -204,6 +204,15 @@ def create_insurance_rate(rate: schemas.InsuranceRateCreate): """保険料率を作成""" with get_connection() as conn: with conn.cursor() as cur: + # 既存の同キー(rate_year, rate_type, calculation_target, prefecture)が存在しないか確認 + cur.execute( + "SELECT 1 FROM insurance_rates WHERE rate_year = %s AND rate_type = %s AND calculation_target = %s AND prefecture = %s LIMIT 1", + (rate.rate_year, rate.rate_type, rate.calculation_target, rate.prefecture) + ) + if cur.fetchone(): + # 重複があればクライアントに分かりやすく 409 を返す + raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="指定された年度・種類・計算対象・都道府県の保険料率は既に存在します") + cur.execute( """ INSERT INTO insurance_rates ( diff --git a/docker-compose.yml b/docker-compose.yml index 969057c..bc168fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,7 @@ services: container_name: njts_nginx restart: unless-stopped ports: - - "80:80" + - "18000:80" volumes: - ./frontend:/usr/share/nginx/html:ro - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf index 9089eb7..ed5fbb3 100644 --- a/docker/nginx/default.conf +++ b/docker/nginx/default.conf @@ -7,7 +7,9 @@ server { # Serve static files location / { - try_files $uri $uri/ =404; + # Try to serve the exact file, then directory, otherwise fall back to index.html + # This ensures accessing / or any SPA route returns /index.html + try_files $uri $uri/ /index.html; } # Proxy API requests to backend container