refactor: use relative URLs and centralize API endpoints (closes #431)#432
Merged
TineoC merged 6 commits intoCodeForPhilly:developfrom Jan 15, 2026
Merged
Conversation
- Updated README.md to include support for PostgreSQL databases via CloudNativePG, AWS RDS, and local Docker Compose. - Added detailed database connection configuration in a new DATABASE_CONNECTION.md file, covering connection type detection, environment variables, and SSL configuration. - Modified dev.env.example to provide examples for different database connection types and SSL mode options. - Updated settings.py to dynamically configure database settings based on the connection type detected from SQL_HOST.
- Introduced a new `endpoints.ts` file to centralize all API endpoint paths for better maintainability and type safety. - Updated various components and services to utilize the new centralized endpoints, enhancing consistency across the codebase. - Created a comprehensive `API_ENDPOINTS_REFACTORING.md` guide detailing the refactoring process and usage patterns for the new endpoints. - Removed hardcoded URLs in favor of the centralized configuration, improving code readability and reducing the risk of errors.
- Update Django URLs to serve all APIs under /api/ prefix - Change frontend to use relative URLs (empty baseURL) instead of environment-specific domains - Create centralized endpoints.ts for maintainable API URL management - Update all frontend components to use centralized endpoints - Remove all VITE_API_BASE_URL and REACT_APP_API_BASE_URL dependencies - Add helper functions for dynamic endpoints with parameters This ensures the same Docker image works in both production and sandbox environments without requiring environment-specific configuration. Fixes: - Frontend calling old domain (balancer.live.k8s.phl.io) - API calls failing after domain migration - /login and /adminportal pages not working Closes CodeForPhilly#431
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After migrating to
https://balancerproject.org/, the frontend was still calling the old API endpoint (balancer.live.k8s.phl.io), causing:Solution
This MR refactors the frontend to use relative URLs instead of environment-specific base URLs, ensuring the same Docker image works in both production and sandbox environments.
Key Changes
Django URL Routing
/api/prefix/admin/outside the API prefixFrontend API Configuration
baseURLfromVITE_API_BASE_URLto empty string''(relative URLs)endpoints.tsfor maintainable API URL managementUpdated All Frontend Components
VITE_API_BASE_URLandREACT_APP_API_BASE_URLdependencies/auth/...→/api/auth/.../v1/api/...→/api/v1/api/.../chatgpt/...→/api/chatgpt/.../ai_settings/...→/api/ai_settings/...Files Changed
Backend:
server/balancer_backend/urls.py- Wrap all APIs under/api/prefixFrontend:
frontend/src/api/apiClient.ts- Use relative URLs and centralized endpointsfrontend/src/api/endpoints.ts- New file - Centralized endpoint configurationfrontend/src/services/actions/auth.tsx- Use centralized auth endpointsfrontend/src/pages/Settings/SettingsManager.tsx- Use centralized endpointsfrontend/src/pages/Files/FileRow.tsx- Use centralized endpointsfrontend/src/pages/DrugSummary/PDFViewer.tsx- Use centralized endpointsDocumentation:
frontend/API_ENDPOINTS_REFACTORING.md- Guide for maintaining endpointsBenefits
✅ Same Docker image works in both production (
balancerproject.org) and sandbox (balancer.sandbox.k8s.phl.io)✅ No environment variables needed for API base URL
✅ Automatic domain detection via relative URLs
✅ Maintainable - All endpoints defined in one place
✅ Type-safe - TypeScript ensures correct endpoint usage
Testing
After deployment, verify:
https://balancerproject.org/loginloads correctlyhttps://balancerproject.org/adminportalloads correctly/api/auth/login/, etc.)Related
Closes #431