From 295e03feb495b93ccf208e6b6d1a295790c4c3fc Mon Sep 17 00:00:00 2001 From: domrichardson <100129001+domrichardson@users.noreply.github.com> Date: Mon, 30 Mar 2026 10:58:36 +0100 Subject: [PATCH] fix: removed hardcoded api url --- .env.example | 2 -- .gitea/workflows/build-and-push.yml | 2 -- ENV_SETUP.md | 5 +---- QUICKSTART.md | 2 +- devops/docker/Dockerfile | 3 --- docker-compose.yml | 2 -- frontend/.env.example | 3 --- frontend/src/services/apiClient.js | 4 +++- 8 files changed, 5 insertions(+), 18 deletions(-) diff --git a/.env.example b/.env.example index 8f4df57..db01aa8 100644 --- a/.env.example +++ b/.env.example @@ -10,8 +10,6 @@ JWT_SECRET=your-super-secret-jwt-key-minimum-32-characters-change-in-production ENCRYPTION_KEY=A5CC60AB92FCA026F5477DC486555882 FRONTEND_URL="http://localhost" -VITE_API_BASE_URL="http://localhost" - # Default Admin DEFAULT_ADMIN_EMAIL=admin@notely.local DEFAULT_ADMIN_USERNAME=admin diff --git a/.gitea/workflows/build-and-push.yml b/.gitea/workflows/build-and-push.yml index 4999be6..2bb1fe0 100644 --- a/.gitea/workflows/build-and-push.yml +++ b/.gitea/workflows/build-and-push.yml @@ -46,8 +46,6 @@ jobs: context: . file: ./devops/docker/Dockerfile push: true - build-args: | - VITE_API_BASE_URL=${{ secrets.VITE_API_BASE_URL }} tags: | ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.short_sha }} diff --git a/ENV_SETUP.md b/ENV_SETUP.md index 0a5e01f..db28e7f 100644 --- a/ENV_SETUP.md +++ b/ENV_SETUP.md @@ -21,7 +21,6 @@ Required or commonly used: - `JWT_SECRET` - `ENCRYPTION_KEY` - `FRONTEND_URL` -- `VITE_API_BASE_URL` - `DEFAULT_ADMIN_EMAIL` - `DEFAULT_ADMIN_USERNAME` - `DEFAULT_ADMIN_PASSWORD` @@ -41,7 +40,6 @@ Optional backend runtime values that Docker Compose will also pass through if pr - MongoDB container: `mongodb://admin:password@mongodb:27017/noteapp?authSource=admin` - Backend port: `8080` - Public frontend URL: `http://localhost` -- Browser API base URL for container builds: `http://localhost` ## 2. `backend/.env` @@ -107,13 +105,12 @@ cp .env.example .env ### Frontend Variables In `frontend/.env.example` -- `VITE_API_BASE_URL` - `VITE_ENV` - `VITE_ENABLE_ANALYTICS` ### Variables Currently Relevant To The Frontend App -- `VITE_API_BASE_URL`: used by the API client +- API requests are sent to the current browser origin (same-origin runtime behavior) The other example values are safe to keep, but the current checked-in frontend code does not actively consume them. diff --git a/QUICKSTART.md b/QUICKSTART.md index 671fc70..abf6ced 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -133,7 +133,7 @@ Check `REDIS_ADDR`, `REDIS_PASSWORD`, and `REDIS_DB`. For local defaults, Redis Check: - backend is running on port `8080` -- frontend `VITE_API_BASE_URL` +- frontend and API are reachable through the same host/origin - Vite proxy settings in `frontend/vite.config.js` ### OAuth callback redirects to the wrong URL diff --git a/devops/docker/Dockerfile b/devops/docker/Dockerfile index 5140236..115f58b 100644 --- a/devops/docker/Dockerfile +++ b/devops/docker/Dockerfile @@ -3,9 +3,6 @@ FROM node:25-alpine AS frontend-builder WORKDIR /frontend -ARG VITE_API_BASE_URL -ENV VITE_API_BASE_URL=${VITE_API_BASE_URL} - COPY frontend/package*.json ./ RUN npm install diff --git a/docker-compose.yml b/docker-compose.yml index eee4ba8..fc849fe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,8 +36,6 @@ services: build: context: . dockerfile: ./devops/docker/Dockerfile - args: - VITE_API_BASE_URL: ${VITE_API_BASE_URL} container_name: notely-app ports: - "${BACKEND_PORT}:${BACKEND_PORT}" diff --git a/frontend/.env.example b/frontend/.env.example index 388b0c8..657dc84 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -1,8 +1,5 @@ # Frontend Environment Example -# API Base URL (Backend server) -VITE_API_BASE_URL=http://localhost:8080 - # Environment VITE_ENV=development diff --git a/frontend/src/services/apiClient.js b/frontend/src/services/apiClient.js index 1ebde59..dfd80fa 100644 --- a/frontend/src/services/apiClient.js +++ b/frontend/src/services/apiClient.js @@ -1,8 +1,10 @@ import axios from "axios"; import { useAuthStore } from "../stores/authStore"; +const runtimeOrigin = typeof window !== "undefined" ? window.location.origin : ""; + const apiClient = axios.create({ - baseURL: import.meta.env.VITE_API_BASE_URL || "http://localhost:8080", + baseURL: runtimeOrigin, withCredentials: true, });