-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
78 lines (59 loc) · 1.99 KB
/
config.py
File metadata and controls
78 lines (59 loc) · 1.99 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
# -------------------------
# Helpers
# -------------------------
from app.utils.config_env import load_env # noqa: F401
load_env()
def _get_int(key: str, default: int) -> int:
try:
return int(os.getenv(key, default))
except (TypeError, ValueError):
return default
# -------------------------
# App (constants + light env override)
# -------------------------
APP_NAME = "TinyURL"
MODE = os.getenv("MODE", "local")
DEBUG = MODE == "local" # auto-debug in local
API_VERSION = os.getenv("API_VERSION", "v1")
# -------------------------
# Server
# -------------------------
HOST = "127.0.0.1"
PORT = _get_int("PORT", 8000)
# If DOMAIN not provided, derive from HOST + PORT
DOMAIN = os.getenv("DOMAIN", f"http://{HOST}:{PORT}")
# -------------------------
# Database
# -------------------------
MONGO_URI = os.getenv("MONGO_URI")
MONGO_DB_NAME = "tiny_url"
MONGO_COLLECTION = os.getenv("MONGO_COLLECTION", "urls")
# Connection timeouts (in milliseconds)
MONGO_TIMEOUT_MS = _get_int("MONGO_TIMEOUT_MS", 10000)
MONGO_SOCKET_TIMEOUT_MS = _get_int("MONGO_SOCKET_TIMEOUT_MS", 20000)
# Connection pool settings
MONGO_MIN_POOL_SIZE = _get_int("MONGO_MIN_POOL_SIZE", 5)
MONGO_MAX_POOL_SIZE = _get_int("MONGO_MAX_POOL_SIZE", 50)
# Retry configuration
MONGO_MAX_RETRIES = _get_int("MONGO_MAX_RETRIES", 10)
MONGO_INITIAL_RETRY_DELAY = 1.0
MONGO_MAX_RETRY_DELAY = 30.0
# Health check interval (in seconds)
HEALTH_CHECK_INTERVAL_SECONDS = _get_int("HEALTH_CHECK_INTERVAL_SECONDS", 30)
# -------------------------
# Cache (constants)
# -------------------------
USE_CACHE = True
CACHE_TTL = 900 # 15 minutes
MAX_CACHE_SIZE = 10_000
MAX_RECENT_URLS = 20
# -------------------------
# Security / Sessions
# -------------------------
SESSION_SECRET = os.getenv("SESSION_SECRET", "super-secret-key")
# -------------------------
# Short URL (constants)
# -------------------------
SHORT_CODE_LENGTH = 6
MAX_URL_LENGTH = 2048