From 5cfe23610e7ed281c35010c2702073a531a1339d Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 26 Jan 2026 22:35:52 -0800 Subject: [PATCH 1/2] feat: use relative URLs for frontend API calls Change frontend to use relative URLs instead of hardcoded localhost values. This enables the same Docker image to work in any environment since nginx handles routing to the backend. Changes: - backendURL now uses '/' (relative path) - containerOrigin derived from window.location.origin - Add getWebSocketURL() helper for WebSocket connections - Remove VITE_* env vars from jest config (no longer needed) - Update tests and snapshots This is a prerequisite for automated deployment where images should be environment-agnostic. Co-Authored-By: Claude Opus 4.5 --- frontend/jest.config.cjs | 6 +- frontend/src/components/HomePage.tsx | 6 +- .../__snapshots__/Hero.test.tsx.snap | 2 +- .../components/__tests__/HomePage.test.tsx | 1 + frontend/src/components/utils/URLs.ts | 62 ++++++++++++------- 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/frontend/jest.config.cjs b/frontend/jest.config.cjs index 94f9284c..a018c6e0 100644 --- a/frontend/jest.config.cjs +++ b/frontend/jest.config.cjs @@ -26,11 +26,7 @@ module.exports = { options: { metaObjectReplacement: { url: 'https://www.url.com', - env: { - VITE_BACKEND_URL: 'http://localhost:8000/', - VITE_FRONTEND_URL: 'http://localhost:80', - VITE_CONTAINER_ORIGIN: 'http://localhost:8080/', - }, + env: {}, }, }, }, diff --git a/frontend/src/components/HomePage.tsx b/frontend/src/components/HomePage.tsx index 01fd0fe7..24eeb8a2 100644 --- a/frontend/src/components/HomePage.tsx +++ b/frontend/src/components/HomePage.tsx @@ -5,7 +5,7 @@ import { Footer } from './HomeComponents/Footer/Footer'; import { SetupGuide } from './HomeComponents/SetupGuide/SetupGuide'; import { FAQ } from './HomeComponents/FAQ/FAQ'; import { Tasks } from './HomeComponents/Tasks/Tasks'; -import { url } from '@/components/utils/URLs'; +import { url, getWebSocketURL } from '@/components/utils/URLs'; import { useNavigate } from 'react-router'; import { motion } from 'framer-motion'; import { toast } from 'react-toastify'; @@ -60,9 +60,7 @@ export const HomePage: React.FC = () => { getTasks(userInfo.email, userInfo.encryption_secret, userInfo.uuid); } - const socketURL = `${url.backendURL.replace(/^http/, 'ws')}ws?clientID=${ - userInfo.uuid - }`; + const socketURL = getWebSocketURL(`ws?clientID=${userInfo.uuid}`); const socket = new WebSocket(socketURL); // socket.onopen = () => console.log('WebSocket connected!'); diff --git a/frontend/src/components/LandingComponents/Hero/__tests__/__snapshots__/Hero.test.tsx.snap b/frontend/src/components/LandingComponents/Hero/__tests__/__snapshots__/Hero.test.tsx.snap index 6d325033..3c459e6d 100644 --- a/frontend/src/components/LandingComponents/Hero/__tests__/__snapshots__/Hero.test.tsx.snap +++ b/frontend/src/components/LandingComponents/Hero/__tests__/__snapshots__/Hero.test.tsx.snap @@ -42,7 +42,7 @@ exports[`Hero component using snapshot renders correctly 1`] = ` class="space-y-4 md:space-y-0 md:space-x-4" >