Skip to content

Refactor Frontend to Use Centralized API Configuration#340

Open
rishabh0510rishabh wants to merge 1 commit intoYugenjr:masterfrom
rishabh0510rishabh:Centralize-API_BASE_URL
Open

Refactor Frontend to Use Centralized API Configuration#340
rishabh0510rishabh wants to merge 1 commit intoYugenjr:masterfrom
rishabh0510rishabh:Centralize-API_BASE_URL

Conversation

@rishabh0510rishabh
Copy link
Copy Markdown
Contributor

📝 Description

This PR refactors the frontend codebase to use a centralized API_BASE_URL constant for all API requests. This change removes hardcoded API strings (e.g., http://localhost:5000/api, /api/), making the application easier to configure for different environments (local, staging, production) via config or environment variables.

🚀 Changes

  • Configuration:
    • Validated and updated frontend/src/utils/api.js to correctly export API_BASE_URL.
    • Configured API_BASE_URL to use import.meta.env.VITE_API_URL with a fallback to http://localhost:5001/api.
    • Safeguarded import.meta.env access to prevent runtime errors in non-Vite environments (e.g., during testing or script execution).
  • Refactoring:
    • Updated frontend/src/hooks/useGrindMapData.js to import and use API_BASE_URL.
    • Updated frontend/src/components/Leaderboard.jsx to use API_BASE_URL.
    • Updated frontend/src/components/GoalDashboard.jsx, Friends.jsx, and BadgeCollection.jsx to replace hardcoded API paths.
  • Code Cleanup:
    • Removed duplicate mock data and function definitions in frontend/src/utils/api.js that were causing linting errors.
    • Restored frontend/package.json which was found to be empty, ensuring standard dependencies and scripts are present.

🔍 Verification

  • Linting: ran npm run lint - PASSED.
  • Build: ran npx vite build - PASSED (Exit Code 0).
  • Runtime Verification: Created and ran a script (verify_api.mjs) to test the mock API functions and API_BASE_URL logic in a simulated Node environment. All checks passed.

📦 Dependencies

  • No new dependencies added. Restored existing ones in package.json.

Related issues #321

Labels: ECWoC26

Update frontend dependencies and lockfile, add lint output, and apply fixes across multiple UI/data files. Changes touch BadgeCollection, Friends, GoalDashboard, Leaderboard, useGrindMapData hook, and api utils to improve data fetching, error handling, and rendering logic (fixes badge rendering, friends list/ordering, leaderboard behavior, and grindmap data mapping).
@Yugenjr
Copy link
Copy Markdown
Owner

Yugenjr commented Feb 9, 2026

KINDLY DONT PUSH THE PACKAGE LOCK FILES AND CAN YOU PLEASE SAY THE EXPLANATION REMOVAL OF SUCH LINES

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.

2 participants