This commit is contained in:
2025-07-09 01:05:45 -05:00
parent 1bbe6e2743
commit d7a610a83b
113 changed files with 1512 additions and 2348 deletions

View File

@ -1,41 +1,47 @@
import os
from dotenv import load_dotenv, find_dotenv
# ─── Load .env from project root or any parent ────────────────────────────────
# ─── Load .env from project root or parents ──────────────────────────────────
dotenv_path = find_dotenv()
if dotenv_path:
load_dotenv(dotenv_path, override=True)
# ─── Paths ───────────────────────────────────────────────────────────────────
# ─── Paths ───────────────────────────────────────────────────────────────────
CONFIG_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = os.path.dirname(CONFIG_DIR)
class Config:
# ─── Environment ─────────────────────────────────────────────────────────────
# ─── Environment ─────────────────────────────────────────────────────────
ENV = (
os.getenv('FLASK_ENV')
or os.getenv('DOCKER_ENV')
or 'production'
).lower()
# ─── Secret Key ──────────────────────────────────────────────────────────────
# ─── Debug / Exceptions ───────────────────────────────────────────────────
DEBUG = ENV != 'production'
PROPAGATE_EXCEPTIONS = True
TRAP_HTTP_EXCEPTIONS = True
# ─── Secret Key ───────────────────────────────────────────────────────────
if ENV == 'production':
SECRET_KEY = os.getenv('SECRET_KEY')
if not SECRET_KEY:
raise RuntimeError(
"SECRET_KEY environment variable not set! "
"Generate one with `openssl rand -hex 32` and export it."
"Generate one with `openssl rand -hex 32`."
)
else:
# dev/test: fall back to env or a random one
SECRET_KEY = os.getenv('SECRET_KEY') or os.urandom(24).hex()
# ─── Uploads ───────────────────────────────────────────────────────────────
# Default to PROJECT_ROOT/static/uploads; if UPLOAD_FOLDER env is set, resolve relative to PROJECT_ROOT
# ─── Uploads ───────────────────────────────────────────────────────────────
_env_upload = os.getenv('UPLOAD_FOLDER', '')
if _env_upload:
# if absolute, use directly; otherwise join to project root
UPLOAD_FOLDER = _env_upload if os.path.isabs(_env_upload) else os.path.join(PROJECT_ROOT, _env_upload)
UPLOAD_FOLDER = (
_env_upload
if os.path.isabs(_env_upload)
else os.path.join(PROJECT_ROOT, _env_upload)
)
else:
UPLOAD_FOLDER = os.path.join(PROJECT_ROOT, "static", "uploads")
@ -48,7 +54,7 @@ class Config:
raise RuntimeError("CELERY_BROKER_URL environment variable not set!")
CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND', CELERY_BROKER_URL)
# ─── MySQL ─────────────────────────────────────────────────────────────────
# ─── MySQL ─────────────────────────────────────────────────────────────────
MYSQL_USER = os.getenv('MYSQL_USER')
MYSQL_PASSWORD = os.getenv('MYSQL_PASSWORD')
if not MYSQL_PASSWORD:
@ -65,11 +71,17 @@ class Config:
)
SQLALCHEMY_TRACK_MODIFICATIONS = False
# ─── Cookies / Session ─────────────────────────────────────────────────────
SESSION_COOKIE_SECURE = True
# ─── Cookies / Session ─────────────────────────────────────────────────────
# only mark cookies Secure in production; in dev we need them over HTTP
if ENV == 'production':
SESSION_COOKIE_SECURE = True
REMEMBER_COOKIE_SECURE = True
else:
SESSION_COOKIE_SECURE = False
REMEMBER_COOKIE_SECURE = False
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'Lax'
REMEMBER_COOKIE_SECURE = True
REMEMBER_COOKIE_HTTPONLY = True
REMEMBER_COOKIE_SAMESITE = 'Lax'
PREFERRED_URL_SCHEME = 'https'
@ -77,6 +89,7 @@ class Config:
# ─── Toggles ────────────────────────────────────────────────────────────────
ENABLE_DB_SEEDING = os.getenv('ENABLE_DB_SEEDING', '0') == '1'
DOCKER_ENV = os.getenv('DOCKER_ENV', 'production')
INVITES_PER_USER = int(os.getenv('INVITES_PER_USER', 5))
# ─── Neo4j ──────────────────────────────────────────────────────────────────
NEO4J_URI = os.getenv('NEO4J_URI', 'bolt://neo4j:7687')
@ -85,8 +98,8 @@ class Config:
if not NEO4J_PASSWORD:
raise RuntimeError("NEO4J_PASSWORD environment variable not set!")
# ─── Misc ──────────────────────────────────────────────────────────────────
STANDARD_IMG_SIZE = tuple(
# ─── Misc ──────────────────────────────────────────────────────────────────
STANDARD_IMG_SIZE = tuple(
map(int, os.getenv('STANDARD_IMG_SIZE', '300x200').split('x'))
)
PLANT_CARDS_BASE_URL = "https://plant.cards"