Setting up the configuration files and refactoring
This commit is contained in:
+19
-17
@@ -1,36 +1,38 @@
|
||||
# app/core/config.py
|
||||
|
||||
from functools import lru_cache
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from pydantic import BaseSettings
|
||||
from typing import List
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# App
|
||||
app_name: str = "URL Shortener API"
|
||||
debug: bool = False
|
||||
app_name: str = "URL Shortener"
|
||||
allowed_hosts: List[str] = ["*"]
|
||||
database_url: str
|
||||
|
||||
# Server
|
||||
# Server settings
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8000
|
||||
base_url: str = "http://localhost:8000"
|
||||
|
||||
# Database
|
||||
database_url: str = "sqlite:///./urls.db"
|
||||
|
||||
# Debug flag
|
||||
debug: bool = True
|
||||
|
||||
# Optional future extensions
|
||||
allowed_hosts: list[str] = ["*"]
|
||||
rate_limit_per_minute: int = 60
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=False,
|
||||
extra="ignore",
|
||||
)
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
env_file_encoding = "utf-8"
|
||||
case_sensitive = False
|
||||
extra = "ignore"
|
||||
|
||||
@lru_cache
|
||||
|
||||
# Cached singleton-style access
|
||||
@lru_cache()
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
|
||||
# Singleton-style access
|
||||
|
||||
# Global settings instance
|
||||
settings = get_settings()
|
||||
Reference in New Issue
Block a user