Skip to content

Commit 49482b6

Browse files
committed
feat: add python-dotenv for environment variable management
- Load `.env` file automatically in `Config` initialization - Add `python-dotenv` dependency with version constraint `>=1.0.0` - Update `pyproject.toml` and `uv.lock` to include `python-dotenv`
1 parent 35a6e4a commit 49482b6

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

backend/app/config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import logging
22
from typing import Literal
33

4+
from dotenv import load_dotenv
45
from pydantic import Field, ValidationError, field_validator
56
from pydantic_settings import BaseSettings
67

78
from app.utils.ip import resolve_hostname, validate_ip_address
89

10+
# Load .env file if it exists
11+
load_dotenv()
12+
913

1014
class Config(BaseSettings):
1115
# Environment
@@ -40,14 +44,14 @@ class Config(BaseSettings):
4044
description="Bearer token for Prometheus metrics endpoint authentication"
4145
)
4246

43-
CORS_DOMAINS: list[str] = Field(default=["*"], validation_alias="APP_CORS_DOMAINS")
44-
4547
ALLOW_CORS_WILDCARD: bool = Field(
4648
default=False,
4749
validation_alias="APP_ALLOW_CORS_WILDCARD",
4850
description="Allow wildcard (*) in CORS domains (disable in production)",
4951
)
5052

53+
CORS_DOMAINS: list[str] = Field(default=["*"], validation_alias="APP_CORS_DOMAINS")
54+
5155
SAVE_USER_AGENT: bool = Field(default=False, validation_alias="APP_SAVE_USER_AGENT")
5256
SAVE_IP_ADDRESS: bool = Field(default=False, validation_alias="APP_SAVE_IP_ADDRESS")
5357

@@ -235,6 +239,7 @@ def verify_trusted_hosts(cls, hosts: list[str]) -> list[str]:
235239
def validate_cors_domains(cls, domains: list[str], info) -> list[str]:
236240
"""Validate CORS domains and warn/error on wildcard."""
237241
if "*" in domains:
242+
# Check if ALLOW_CORS_WILDCARD is in the data (field name, not alias)
238243
allow_wildcard = info.data.get("ALLOW_CORS_WILDCARD", False)
239244

240245
if not allow_wildcard:

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies = [
1313
"asyncpg>=0.29",
1414
"pydantic>=2.7",
1515
"pydantic-settings>=2.12.0",
16+
"python-dotenv>=1.0.0",
1617
"uuid>=1.30",
1718
"aiofiles>=25.1.0",
1819
"alembic>=1.17.2",

backend/uv.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)