From 8c3a7fa9339c9046199d33171d4a67861f76f11b Mon Sep 17 00:00:00 2001 From: Milix-M <70957923+Milix-M@users.noreply.github.com> Date: Mon, 18 Aug 2025 22:10:58 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=A7=E8=A8=AD=E5=AE=9A=E3=82=92=E8=A1=8C=E3=81=88?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.py | 15 ++++++++------- src/common/config.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 src/common/config.py diff --git a/src/app.py b/src/app.py index 3c799bf..abb9bc0 100644 --- a/src/app.py +++ b/src/app.py @@ -8,6 +8,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from src.routers import emoji +from src.common.config import settings # ログ設定 logging.basicConfig( @@ -16,19 +17,19 @@ logger = logging.getLogger(__name__) app = FastAPI( - title="Emoji API", - description="API for generating custom emoji images with text.", - version="1.0.0", + title=settings.PROJECT_NAME, + description=settings.DESCRIPTION, + version=settings.PROJECT_VERSION, ) """FastAPI application instance.""" # CORS設定 app.add_middleware( CORSMiddleware, - allow_origins=["*"], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], + allow_origins=settings.CORS_ORIGINS, + allow_credentials=settings.CORS_ALLOW_CREDENTIALS, + allow_methods=settings.CORS_ALLOW_METHODS, + allow_headers=settings.CORS_ALLOW_HEADERS, ) # ルーターの登録 diff --git a/src/common/config.py b/src/common/config.py new file mode 100644 index 0000000..94b4a3a --- /dev/null +++ b/src/common/config.py @@ -0,0 +1,15 @@ +from typing import List + +class AppSettings: + """Application settings.""" + PROJECT_NAME: str = "Emoji API" + PROJECT_VERSION: str = "1.0.0" + DESCRIPTION: str = "API for generating custom emoji images with text." + + # CORS settings + CORS_ORIGINS: List[str] = ["*"] + CORS_ALLOW_CREDENTIALS: bool = True + CORS_ALLOW_METHODS: List[str] = ["*"] + CORS_ALLOW_HEADERS: List[str] = ["*"] + +settings = AppSettings()