-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
50 lines (36 loc) · 1.45 KB
/
Copy pathconfig.py
File metadata and controls
50 lines (36 loc) · 1.45 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
import os
from datetime import timedelta
def _parse_cors_origins() -> str | list[str]:
"""Flask-CORS accepts '*' or a list of origins; support comma-separated env."""
raw = os.getenv("CORS_ORIGINS", "*").strip()
if raw == "*":
return "*"
parts = [p.strip() for p in raw.split(",") if p.strip()]
return parts if parts else "*"
def _database_url() -> str:
"""Normalize DATABASE_URL for SQLAlchemy (Render/Heroku use postgres://)."""
uri = os.getenv("DATABASE_URL", "sqlite:///litup.db")
if uri.startswith("postgres://"):
uri = "postgresql://" + uri[len("postgres://") :]
return uri
class Config:
# 32+ chars avoids PyJWT "insecure key length" warnings for HS256 in dev
SECRET_KEY = os.getenv(
"SECRET_KEY",
"dev-please-change-this-secret-key-32bytes!!",
)
# Works for SQLite (dev) and Postgres (prod via DATABASE_URL)
SQLALCHEMY_DATABASE_URI = _database_url()
SQLALCHEMY_TRACK_MODIFICATIONS = False
JWT_SECRET_KEY = os.getenv("JWT_SECRET_KEY", SECRET_KEY)
JWT_ACCESS_TOKEN_EXPIRES = timedelta(
minutes=int(os.getenv("JWT_ACCESS_TOKEN_MINUTES", "60"))
)
# Allow separate hosting of frontend (GitHub Pages) during dev/prod
CORS_ORIGINS = _parse_cors_origins()
class DevelopmentConfig(Config):
ENV = "development"
DEBUG = True
class ProductionConfig(Config):
ENV = "production"
DEBUG = False