43 lines
1.9 KiB
Python

import os.path as path
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from starlette import status
import src.static as static
from src.controller import (bio, bio_download, healthcheck, login, logout,
master_mainte, menu, root, ultmarc)
from src.error.exception_handler import http_exception_handler
from src.error.exceptions import UnexpectedException
app = FastAPI()
# 静的ファイルをマウント
app.mount('/static', StaticFiles(directory=path.dirname(static.__file__)), name='static')
# ルートパス。顧客ログイン画面にリダイレクトさせる
app.include_router(root.router)
# ログイン関連のルーター
app.include_router(login.router, prefix='/login')
# ログアウト関連のルーター
app.include_router(logout.router, prefix='/logout')
# メニュー画面関連のルーター
app.include_router(menu.router, prefix='/menu')
# 生物由来関連のルーター
app.include_router(bio.router, prefix='/bio')
# アルトマークデータ照会のルーター
app.include_router(ultmarc.router, prefix='/ultmarc')
# 生物由来のダウンロード用APIルーター。
# クライアントから非同期呼出しされるため、共通ルーターとは異なる扱いとする。
app.include_router(bio_download.router, prefix='/bio')
# マスタメンテ
app.include_router(master_mainte.router, prefix='/masterMainte')
# ヘルスチェック用のルーター
app.include_router(healthcheck.router, prefix='/healthcheck')
# エラー発生時にログアウト画面に遷移させるハンドラー
app.add_exception_handler(status.HTTP_401_UNAUTHORIZED, http_exception_handler)
app.add_exception_handler(status.HTTP_403_FORBIDDEN, http_exception_handler)
# サーバーエラーが発生した場合のハンドラー。HTTPExceptionではハンドリングできないため、個別に設定
app.add_exception_handler(UnexpectedException, http_exception_handler)