Skip to content

Commit

Permalink
impr: fix env modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ukwhatn committed Jun 1, 2024
1 parent 4d0f8f1 commit fb16a12
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 2 additions & 0 deletions compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ services:
env_file:
- ./envs/db.env
- ./envs/server.env
environment:
- ENV_MODE=development
restart: always
depends_on:
db:
Expand Down
2 changes: 2 additions & 0 deletions compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ services:
env_file:
- ./envs/db.env
- ./envs/server.env
environment:
- ENV_MODE=production
restart: always
depends_on:
db:
Expand Down
4 changes: 0 additions & 4 deletions nginx/conf.d/server.prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ upstream server {
server server:80;
}

upstream front {
server front:5173;
}

server{
listen 80;

Expand Down
15 changes: 6 additions & 9 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,24 @@
from util.env import get_env

# get environment mode
env_mode = get_env("ENV_MODE", "development")
env_mode = get_env("ENV_MODE", "production")

# logger config
logging.basicConfig(level=logging.WARN)
logger = logging.getLogger("uvicorn")

# production時,docsを表示しない
app_params = {}
if env_mode == "development":
logger.setLevel(level=logging.DEBUG)
app_params["docs_url"] = "/api/docs"
app_params["redoc_url"] = "/api/redoc"
app_params["openapi_url"] = "/api/openapi.json"
elif env_mode == "production":
logger.setLevel(level=logging.INFO)

# production時,docsを表示しない
app_params = {}
if env_mode == "production":
app_params["docs_url"] = None
app_params["redoc_url"] = None
app_params["openapi_url"] = None
else:
app_params["docs_url"] = "/api/docs"
app_params["redoc_url"] = "/api/redoc"
app_params["openapi_url"] = "/api/openapi.json"

# create app
app = FastAPI(**app_params)
Expand Down

0 comments on commit fb16a12

Please sign in to comment.