Skip to content

[BUG]: Four services read VITE_BASE_URL with no fallback — silent "Failed to fetch" when unset #465

Description

@RounakKumarAgarwal

Bug Description

Several frontend services read VITE_BASE_URL directly with no fallback value, while most other files in the codebase guard it with || 'http://localhost:1313'. When VITE_BASE_URL is not set (e.g. a new contributor clones the repo and forgets to create frontend/.env), baseURL becomes undefined, so every request is sent to undefined/<path> and fails silently.

Affected files (no fallback):

  • src/services/profileService.ts
  • src/services/vsbot.ts
  • src/services/adminService.ts
  • src/services/leaderboardService.ts
// e.g. profileService.ts
const baseURL = import.meta.env.VITE_BASE_URL;   // undefined if not set
// → fetch(`${baseURL}/user/fetchprofile`) hits "undefined/user/fetchprofile"

For contrast, other files handle this correctly:

const baseURL = import.meta.env.VITE_BASE_URL || 'http://localhost:1313';
// e.g. transcriptService.ts, gamificationService.ts, CommentTree.tsx, etc.

This is a separate issue from #434 — that one is about the wrong variable name (VITE_API_URL never being defined). This is about the correct variable (VITE_BASE_URL) being read without a fallback, causing an inconsistent developer experience and a confusing, hard-to-trace "Failed to fetch" for anyone who hasn't set the env var.

Steps to Reproduce

  1. Clone the repo and do NOT create a frontend/.env file (or leave VITE_BASE_URL unset).
  2. Run the frontend dev server.
  3. Navigate to a page that uses one of the affected services (e.g. Profile, Leaderboard).
  4. Observe the request goes to undefined/... and fails with "Failed to fetch"; no clear indication that the env var is the cause.

Logs and Screenshots

$ grep -rn "VITE_BASE_URL;" frontend/src/services/
frontend/src/services/profileService.ts:1:const baseURL = import.meta.env.VITE_BASE_URL;
frontend/src/services/vsbot.ts:3:const baseURL = import.meta.env.VITE_BASE_URL;
frontend/src/services/adminService.ts:1:const baseURL = import.meta.env.VITE_BASE_URL;
frontend/src/services/leaderboardService.ts:1:const baseURL = import.meta.env.VITE_BASE_URL;

Environment Details

Impact

Low - Minor inconvenience

Code of Conduct

  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions