Skip to content

fix: replace hardcoded API URL with environment variable#64

Open
ShrutiiShinde05 wants to merge 1 commit into
niharika-mente:mainfrom
ShrutiiShinde05:fix-api-url
Open

fix: replace hardcoded API URL with environment variable#64
ShrutiiShinde05 wants to merge 1 commit into
niharika-mente:mainfrom
ShrutiiShinde05:fix-api-url

Conversation

@ShrutiiShinde05

@ShrutiiShinde05 ShrutiiShinde05 commented Jun 16, 2026

Copy link
Copy Markdown

Description

Replaced the hardcoded API URL (http://localhost:5001/api) with an environment-based configuration.

Changes

  • Replaced hardcoded URL with import.meta.env.VITE_API_URL || "/api"

Benefits

  • Supports different environments (development, staging, production)
  • Prevents deployment issues caused by localhost references
  • Improves configuration flexibility

Summary by CodeRabbit

  • Chores
    • Updated API endpoint configuration to support environment-based URLs, enabling more flexible deployment across different environments instead of using a fixed endpoint.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

API_URL in frontend/src/lib/axios.js is changed from the hardcoded string "http://localhost:5001/api" to import.meta.env.VITE_API_URL || "/api". All other axios client configuration is unchanged.

Changes

Axios API URL from environment variable

Layer / File(s) Summary
API_URL derived from VITE_API_URL env variable
frontend/src/lib/axios.js
API_URL is now computed from import.meta.env.VITE_API_URL with "/api" as the fallback, replacing the literal "http://localhost:5001/api".

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related issues

Poem

A rabbit once hopped to deploy with glee,
But localhost kept hiding where the backend should be.
So I swapped out the hardcode for a Vite env key,
With "/api" as fallback — hip hip, hooray! 🐇
No more localhost woes on production day!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing a hardcoded API URL with an environment variable configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@ShrutiiShinde05

Copy link
Copy Markdown
Author

Hi! @niharika-mente I've submitted a PR for this issue.

The hardcoded API URL has been replaced with an environment-based configuration using VITE_API_URL with a fallback to /api.

I'd appreciate a review when you have time. Thank you!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
frontend/src/lib/axios.js (1)

3-3: Add environment variable setup documentation and .env file for development.

The change introduces a silent fallback to "/api" when VITE_API_URL is not set. While the /api path correctly matches the backend route structure (/api/notes and /api/auth), the current setup lacks configuration guidance:

  • No .env or .env.example exists in the frontend directory to document the variable
  • No CI/CD pipeline is configured to set VITE_API_URL for different deployment environments
  • No documentation explains that this variable is optional but useful for non-relative-path deployments (e.g., separate domains, proxy configurations)

For development flexibility and clarity, add a frontend/.env.example documenting VITE_API_URL, and update the README to explain when and how to override the default /api fallback. This improves maintainability without blocking the current change.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/lib/axios.js` at line 3, The code change in axios.js correctly
implements a fallback to "/api" for the API_URL when VITE_API_URL is not set,
but the setup lacks proper documentation. Create a frontend/.env.example file
that documents the VITE_API_URL environment variable with an example value, and
update the project README to explain that VITE_API_URL is an optional
configuration variable useful for deployments where the frontend and backend are
on different domains or behind a proxy. Make clear that when not set, the
default relative path "/api" is used, matching the backend route structure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@frontend/src/lib/axios.js`:
- Line 3: The code change in axios.js correctly implements a fallback to "/api"
for the API_URL when VITE_API_URL is not set, but the setup lacks proper
documentation. Create a frontend/.env.example file that documents the
VITE_API_URL environment variable with an example value, and update the project
README to explain that VITE_API_URL is an optional configuration variable useful
for deployments where the frontend and backend are on different domains or
behind a proxy. Make clear that when not set, the default relative path "/api"
is used, matching the backend route structure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f49b9ee8-0314-4cab-928c-8673a8ac6d7c

📥 Commits

Reviewing files that changed from the base of the PR and between b13fd53 and a3cb4d0.

📒 Files selected for processing (1)
  • frontend/src/lib/axios.js

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.

1 participant