Skip to content

Commit a702e19

Browse files
committed
chore: configuration and infrastructure polish
- Add Redis persistence volume - Extract REDIS_HOST, REDIS_PORT, and CORS_ORIGINS to environment variables
1 parent 79bc9f9 commit a702e19

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ DEBUG=False
1515

1616
# Cache settings - Enable to improve performance
1717
CACHE_ENABLED=True
18+
19+
# Redis Configuration
20+
REDIS_HOST=redis
21+
REDIS_PORT=6379
22+
23+
# CORS Configuration
24+
# Comma-separated list of allowed origins
25+
CORS_ORIGINS=https://devb.io,https://beta.devb.io,http://localhost:3000,http://localhost:8080

api/main.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Initialize Redis client
2929
if Settings.CACHE_ENABLED:
30-
redis_client = redis.Redis(host='redis', port=6379, db=0)
30+
redis_client = redis.Redis(host=Settings.REDIS_HOST, port=Settings.REDIS_PORT, db=0)
3131

3232

3333
class APIKeyMiddleware(BaseHTTPMiddleware):
@@ -162,17 +162,10 @@ async def fetch_linkedin_profile(username: Annotated[str, Depends(verify_linkedi
162162

163163

164164

165-
ALLOWED_ORIGINS = [
166-
"https://devb.io",
167-
"https://beta.devb.io",
168-
"http://localhost:3000", # For local development
169-
"http://localhost:8080"
170-
]
171-
172165
# Add CORS middleware with specific origins
173166
app.add_middleware(
174167
CORSMiddleware,
175-
allow_origins=ALLOWED_ORIGINS, # Use the whitelist instead of "*"
168+
allow_origins=Settings.CORS_ORIGINS, # Use the whitelist instead of "*"
176169
allow_credentials=True,
177170
allow_methods=["GET", "OPTIONS"], # Specify allowed methods
178171
allow_headers=["Authorization", "Content-Type", "X-API-Key"], # Specify allowed headers

config/settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ class Settings:
3737
BLACKLISTED_USERS = json.load(f)
3838

3939
BLACKLISTED_USERS = {user.lower() for user in BLACKLISTED_USERS}
40-
REDIS_HOST = "redis://redis:6379/0"
40+
41+
# Redis configuration
42+
REDIS_HOST = os.getenv("REDIS_HOST", "redis")
43+
REDIS_PORT = int(os.getenv("REDIS_PORT", "6379"))
44+
45+
# CORS configuration
46+
CORS_ORIGINS = os.getenv("CORS_ORIGINS", "https://devb.io,https://beta.devb.io,http://localhost:3000,http://localhost:8080").split(",")
47+
4148
API_URL = "https://user.devb.io"
4249
DEFAULT_CACHE_TTL = 3600 * 24 * 7 # 1 week
4350
CACHE_ENABLED = os.getenv("CACHE_ENABLED", "true").lower() == "true"

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ services:
1818
image: redis:7.2-alpine
1919
ports:
2020
- "6378:6379"
21+
volumes:
22+
- redis_data:/data
2123
networks:
2224
- app-network
2325

2426
networks:
2527
app-network:
2628
driver: bridge
2729

30+
volumes:
31+
redis_data:
32+
2833

0 commit comments

Comments
 (0)