51 lines
2.2 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_api, healthcheck, login, logout,
master_mainte, menu, root, ultmarc)
from src.core import task
from src.error.exception_handler import http_exception_handler
from src.error.exceptions import UnexpectedException
from src.middleware.middleware import SecurityHeadersMiddleware
app = FastAPI(openapi_url=None)
# 静的ファイルをマウント
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_api.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)
# セキュリティヘッダー設定はミドルウェアで処理する
app.add_middleware(SecurityHeadersMiddleware)
# サーバー起動時のイベント
app.add_event_handler('startup', task.create_start_app_handler())