Skip to content

feat: replace hardcoded ports/URLs with environment variables#1135

Open
saakshigupta2002 wants to merge 1 commit intoAOSSIE-Org:mainfrom
saakshigupta2002:feature/env-config-ports-urls
Open

feat: replace hardcoded ports/URLs with environment variables#1135
saakshigupta2002 wants to merge 1 commit intoAOSSIE-Org:mainfrom
saakshigupta2002:feature/env-config-ports-urls

Conversation

@saakshigupta2002
Copy link

Pull Request: Replace Hardcoded Ports/URLs with Environment Variables

PR Title

feat: replace hardcoded ports/URLs with environment variables

Summary

  • Added environment variable support for backend and sync microservice server configuration
  • Updated frontend to use Vite environment variables with sensible fallback defaults
  • Documented all new environment variables in .env.example

Motivation and Context

Ports and URLs were hardcoded throughout the codebase, making it impossible to:

  • Run multiple instances on the same machine
  • Deploy to cloud platforms with dynamic ports
  • Easily switch between dev/staging/production environments

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)

  • Added BACKEND_HOST (default: localhost)
  • Added BACKEND_PORT (default: 52123)
  • Added SYNC_MICROSERVICE_HOST (default: localhost)
  • Added SYNC_MICROSERVICE_PORT (default: 52124)
  • Made SYNC_MICROSERVICE_URL configurable (auto-constructed from host:port or override)

Backend Server (backend/main.py)

  • Updated OpenAPI servers configuration to use dynamic URL
  • Updated Uvicorn server config to use environment variables

Sync Microservice Configuration (sync-microservice/app/config/settings.py)

  • Added BACKEND_HOST and BACKEND_PORT configuration
  • Made PRIMARY_BACKEND_URL configurable
  • Added SYNC_MICROSERVICE_HOST and SYNC_MICROSERVICE_PORT
  • Made SYNC_MICROSERVICE_URL configurable

Sync Microservice Server (sync-microservice/main.py)

  • Updated Uvicorn server config to use environment variables

Frontend Configuration (frontend/src/config/Backend.ts)

  • Updated to use Vite environment variables (import.meta.env)
  • Added fallback to default values for development

Environment Template (.env.example)

  • Added comprehensive documentation for all new environment variables
  • Organized into logical sections (Backend, Sync Microservice, Frontend)

How to Test

Test with default configuration (no changes needed):

# Backend
cd backend && python main.py
# Should start on localhost:52123

# Sync Microservice
cd sync-microservice && python main.py
# Should start on localhost:52124

Test with custom ports:

# Backend on custom port
BACKEND_PORT=8000 python backend/main.py
# Should start on localhost:8000

# Sync Microservice on custom port
SYNC_MICROSERVICE_PORT=8001 python sync-microservice/main.py
# Should start on localhost:8001

Test Frontend with custom backend URL:

cd frontend
VITE_BACKEND_URL=http://localhost:8000 npm run dev

Environment Variables Reference

Variable Default Description
BACKEND_HOST localhost Host for the main backend server
BACKEND_PORT 52123 Port for the main backend server
SYNC_MICROSERVICE_HOST localhost Host for the sync microservice
SYNC_MICROSERVICE_PORT 52124 Port for the sync microservice
PRIMARY_BACKEND_URL Auto-constructed Full URL for the main backend
SYNC_MICROSERVICE_URL Auto-constructed Full URL for the sync microservice
VITE_BACKEND_URL http://localhost:52123 Frontend: Backend URL
VITE_SYNC_MICROSERVICE_URL http://localhost:52124 Frontend: Sync microservice URL

Backward 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

  • Code follows the project's coding standards
  • Changes are backward compatible
  • Environment variables documented in .env.example
  • Tested with default configuration
  • Tested with custom configuration

Related Issue

Fixes #1134


Files Changed

  • .env.example - Added environment variable documentation
  • backend/app/config/settings.py - Added env var support for server configuration
  • backend/main.py - Updated to use config variables
  • sync-microservice/app/config/settings.py - Added env var support
  • sync-microservice/main.py - Updated to use config variables
  • frontend/src/config/Backend.ts - Added Vite env var support

- 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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

Warning

Rate limit exceeded

@saakshigupta2002 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 22 minutes and 47 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Configuration: Replace hardcoded ports/URLs with environment variables

1 participant