feat: replace hardcoded ports/URLs with environment variables#1135
feat: replace hardcoded ports/URLs with environment variables#1135saakshigupta2002 wants to merge 1 commit intoAOSSIE-Org:mainfrom
Conversation
- Add environment variable support for backend server configuration (BACKEND_HOST, BACKEND_PORT) - Add environment variable support for sync microservice configuration (SYNC_MICROSERVICE_HOST, SYNC_MICROSERVICE_PORT, SYNC_MICROSERVICE_URL) - Update frontend to use Vite environment variables with fallback defaults (VITE_BACKEND_URL, VITE_SYNC_MICROSERVICE_URL) - Update .env.example with documentation for all new environment variables This allows: - Running multiple instances on the same machine - Deploying to cloud platforms with dynamic ports - Easy switching between dev/staging/production environments Fixes AOSSIE-Org#1134
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Pull Request: Replace Hardcoded Ports/URLs with Environment Variables
PR Title
Summary
.env.exampleMotivation and Context
Ports and URLs were hardcoded throughout the codebase, making it impossible to:
This PR addresses these concerns by introducing configurable environment variables while maintaining backward compatibility with existing default values.
Changes Made
Backend Configuration (
backend/app/config/settings.py)BACKEND_HOST(default:localhost)BACKEND_PORT(default:52123)SYNC_MICROSERVICE_HOST(default:localhost)SYNC_MICROSERVICE_PORT(default:52124)SYNC_MICROSERVICE_URLconfigurable (auto-constructed from host:port or override)Backend Server (
backend/main.py)Sync Microservice Configuration (
sync-microservice/app/config/settings.py)BACKEND_HOSTandBACKEND_PORTconfigurationPRIMARY_BACKEND_URLconfigurableSYNC_MICROSERVICE_HOSTandSYNC_MICROSERVICE_PORTSYNC_MICROSERVICE_URLconfigurableSync Microservice Server (
sync-microservice/main.py)Frontend Configuration (
frontend/src/config/Backend.ts)import.meta.env)Environment Template (
.env.example)How to Test
Test with default configuration (no changes needed):
Test with custom ports:
Test Frontend with custom backend URL:
cd frontend VITE_BACKEND_URL=http://localhost:8000 npm run devEnvironment Variables Reference
BACKEND_HOSTlocalhostBACKEND_PORT52123SYNC_MICROSERVICE_HOSTlocalhostSYNC_MICROSERVICE_PORT52124PRIMARY_BACKEND_URLSYNC_MICROSERVICE_URLVITE_BACKEND_URLhttp://localhost:52123VITE_SYNC_MICROSERVICE_URLhttp://localhost:52124Backward Compatibility
All existing deployments will continue to work without any changes, as all environment variables have sensible defaults that match the previous hardcoded values.
Checklist
.env.exampleRelated Issue
Fixes #1134
Files Changed
.env.example- Added environment variable documentationbackend/app/config/settings.py- Added env var support for server configurationbackend/main.py- Updated to use config variablessync-microservice/app/config/settings.py- Added env var supportsync-microservice/main.py- Updated to use config variablesfrontend/src/config/Backend.ts- Added Vite env var support