🧹 Remove hardcoded API URL fallback and add environment validation#7
Conversation
- Removed 'http://localhost:3000' fallback for VITE_API_URL in frontend/src/services/api.ts - Added runtime check to throw an error if VITE_API_URL is not defined - Created frontend/.env.example to document required environment variables - Updated frontend/src/test/setup.ts to mock VITE_API_URL for tests Co-authored-by: davidraehles <6085055+davidraehles@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR tightens frontend configuration by removing the hardcoded API base URL fallback and enforcing VITE_API_URL as a required environment variable so the app fails fast when misconfigured.
Changes:
- Removed the
http://localhost:3000fallback and added a runtime validation/throw whenVITE_API_URLis missing. - Updated Vitest setup to stub
VITE_API_URLfor the test environment. - Added
frontend/.env.exampledocumenting the required variable.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/src/services/api.ts | Enforces VITE_API_URL presence and removes the hardcoded localhost fallback. |
| frontend/src/test/setup.ts | Stubs VITE_API_URL so importing the API client in tests doesn’t throw. |
| frontend/.env.example | Documents the required VITE_API_URL env var for local/dev setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| */ | ||
|
|
||
| import { expect, afterEach } from 'vitest'; | ||
| import { expect, afterEach, vi } from 'vitest'; |
There was a problem hiding this comment.
expect is imported but never used in this setup file (Vitest globals are enabled in vite.config.ts, and this file already imports from vitest for afterEach/vi). This will trip @typescript-eslint/no-unused-vars; remove expect from the import (or disable the rule for this line if you intentionally want the binding).
| import { expect, afterEach, vi } from 'vitest'; | |
| import { afterEach, vi } from 'vitest'; |
There was a problem hiding this comment.
Removed unused expect import from test setup.
There was a problem hiding this comment.
Good catch! I've removed the unused expect import from the test setup.
Co-authored-by: davidraehles <6085055+davidraehles@users.noreply.github.com>
🎯 What: Removed the hardcoded fallback value for the API URL in the frontend and replaced it with a strict environment variable requirement.
💡 Why: This ensures that the application configuration is strictly managed via the environment, preventing accidental connections to the wrong backend and improving maintainability. Added validation ensures the app fails fast with a clear error message if the configuration is missing.
✅ Verification:
VITE_API_URLis correctly read from the environment..env.examplefile for documentation.✨ Result: Improved configuration health and robust environment variable handling.
PR created automatically by Jules for task 8975384767320290455 started by @davidraehles