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() load_dotenv()
from fastapi import FastAPI, Request from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse, RedirectResponse
from pydantic import ValidationError from pydantic import ValidationError
from fastapi.middleware.cors import CORSMiddleware 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) #@app.get("/", include_in_schema=False)
def root(): #def root():
return RedirectResponse(url="/index.html") # return RedirectResponse(url="/index.html")
# ───────────────────────── # ─────────────────────────
# ルーター登録(※ 必ず app 定義の後) # ルーター登録(※ 必ず app 定義の後)
@@ -124,10 +124,18 @@ app.mount(
# ) # )
# フロントエンドファイル配信 # フロントエンドファイル配信
frontend_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "frontend") from fastapi.staticfiles import StaticFiles
if os.path.exists(frontend_path): 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( app.mount(
"/frontend", "/",
StaticFiles(directory=frontend_path, html=True), StaticFiles(directory=frontend_path, html=True),
name="frontend", name="frontend",
) )

View File

@@ -204,6 +204,15 @@ def create_insurance_rate(rate: schemas.InsuranceRateCreate):
"""保険料率を作成""" """保険料率を作成"""
with get_connection() as conn: with get_connection() as conn:
with conn.cursor() as cur: 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( cur.execute(
""" """
INSERT INTO insurance_rates ( INSERT INTO insurance_rates (

View File

@@ -18,7 +18,7 @@ services:
container_name: njts_nginx container_name: njts_nginx
restart: unless-stopped restart: unless-stopped
ports: ports:
- "80:80" - "18000:80"
volumes: volumes:
- ./frontend:/usr/share/nginx/html:ro - ./frontend:/usr/share/nginx/html:ro
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro

View File

@@ -7,7 +7,9 @@ server {
# Serve static files # Serve static files
location / { 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 # Proxy API requests to backend container