-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
46 lines (36 loc) · 1.68 KB
/
config.py
File metadata and controls
46 lines (36 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Configuration module for the Library Management System.
Loads settings from environment variables with sensible defaults.
"""
import os
from typing import List
def get_list_from_env(key: str, default: str) -> List[str]:
"""Parse a comma-separated environment variable into a list."""
value = os.getenv(key, default)
return [item.strip() for item in value.split(",") if item.strip()]
# Server configuration
HOST: str = os.getenv("HOST", "127.0.0.1")
PORT: int = int(os.getenv("PORT", "8000"))
DEBUG: bool = os.getenv("DEBUG", "false").lower() in ("true", "1", "yes")
# CORS configuration
# In production, set CORS_ORIGINS to your specific domain(s)
# Example: CORS_ORIGINS=https://example.com,https://www.example.com
CORS_ORIGINS: List[str] = get_list_from_env(
"CORS_ORIGINS",
"http://localhost:8000,http://127.0.0.1:8000,http://localhost:3000,null"
)
CORS_ALLOW_CREDENTIALS: bool = os.getenv("CORS_ALLOW_CREDENTIALS", "true").lower() in ("true", "1", "yes")
CORS_ALLOW_METHODS: List[str] = get_list_from_env("CORS_ALLOW_METHODS", "GET,POST,PUT,DELETE,OPTIONS")
CORS_ALLOW_HEADERS: List[str] = get_list_from_env("CORS_ALLOW_HEADERS", "Content-Type,Authorization")
# Data configuration
LIBRARY_FILE: str = os.getenv("LIBRARY_FILE", "library.json")
# Logging configuration
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
LOG_FILE: str = os.getenv("LOG_FILE", "") # Empty means stdout only
LOG_FORMAT: str = os.getenv(
"LOG_FORMAT",
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
# OpenLibrary API configuration
OPENLIBRARY_BASE_URL: str = os.getenv("OPENLIBRARY_BASE_URL", "https://openlibrary.org")
OPENLIBRARY_TIMEOUT: int = int(os.getenv("OPENLIBRARY_TIMEOUT", "10"))