Skip to content

Commit de5c7d1

Browse files
committed
feat: Add FastAPI backend with CORS configuration and initial API endpoints.
1 parent 0aa1fe2 commit de5c7d1

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ UNSPLASH_ACCESS_KEY=your_unsplash_access_key_here
7676

7777
# PORT=8000
7878

79+
# ========================================
80+
# CORS (Cross-Origin Resource Sharing)
81+
# ========================================
82+
# Comma-separated list of allowed origins for CORS
83+
# Development: http://localhost:3000
84+
# Production: Add your frontend domain(s)
85+
# Example: CORS_ORIGINS=http://localhost:3000,https://your-app.vercel.app
86+
87+
CORS_ORIGINS=http://localhost:3000
88+
7989
# ========================================
8090
# EMAIL SERVICE (SMTP) - Optional
8191
# ========================================

backend/app.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,49 @@
166166
api_limiter = None
167167
RateLimitExceededError = Exception
168168

169+
# =============================================================================
170+
# ENVIRONMENT VALIDATION
171+
# =============================================================================
172+
def validate_environment():
173+
"""Validate required environment variables on startup."""
174+
required_vars = {
175+
"GROQ_API_KEY": "AI content generation",
176+
"LINKEDIN_CLIENT_ID": "LinkedIn OAuth",
177+
"LINKEDIN_CLIENT_SECRET": "LinkedIn OAuth",
178+
}
179+
180+
optional_but_recommended = {
181+
"GITHUB_CLIENT_ID": "GitHub OAuth (private repos)",
182+
"GITHUB_CLIENT_SECRET": "GitHub OAuth (private repos)",
183+
"UNSPLASH_ACCESS_KEY": "Image generation",
184+
}
185+
186+
missing_required = []
187+
missing_optional = []
188+
189+
for var, purpose in required_vars.items():
190+
if not os.getenv(var):
191+
missing_required.append(f" - {var}: {purpose}")
192+
193+
for var, purpose in optional_but_recommended.items():
194+
if not os.getenv(var):
195+
missing_optional.append(f" - {var}: {purpose}")
196+
197+
if missing_required:
198+
print("\n⚠️ WARNING: Missing REQUIRED environment variables:")
199+
for msg in missing_required:
200+
print(msg)
201+
print(" Some features will not work until these are set.\n")
202+
203+
if missing_optional:
204+
print("\n💡 TIP: Missing OPTIONAL environment variables:")
205+
for msg in missing_optional:
206+
print(msg)
207+
print(" These are recommended for full functionality.\n")
208+
209+
# Run validation on import
210+
validate_environment()
211+
169212
app = FastAPI(
170213
title="LinkedIn Post Bot API",
171214
description="""
@@ -207,9 +250,14 @@
207250
init_settings_db()
208251

209252
# Add CORS middleware
253+
# CORS_ORIGINS env var should be comma-separated list of allowed origins
254+
# Example: CORS_ORIGINS=http://localhost:3000,https://your-app.vercel.app
255+
CORS_ORIGINS = os.getenv("CORS_ORIGINS", "http://localhost:3000").split(",")
256+
CORS_ORIGINS = [origin.strip() for origin in CORS_ORIGINS if origin.strip()]
257+
210258
app.add_middleware(
211259
CORSMiddleware,
212-
allow_origins=["http://localhost:3000"],
260+
allow_origins=CORS_ORIGINS,
213261
allow_credentials=True,
214262
allow_methods=["*"],
215263
allow_headers=["*"],

0 commit comments

Comments
 (0)