From f5aa376e314dbe482f5dc30d3bd003fcaad1d540 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Thu, 23 Oct 2025 15:38:17 +0200 Subject: [PATCH] changed static paths to relative api paths so useable without cors --- frontend/src/pages/Setup/Setup.tsx | 4 +++- .../src/services/shiftAssignmentService.ts | 2 -- frontend/src/services/shiftPlanService.ts | 22 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frontend/src/pages/Setup/Setup.tsx b/frontend/src/pages/Setup/Setup.tsx index 63d6c43..c47638e 100644 --- a/frontend/src/pages/Setup/Setup.tsx +++ b/frontend/src/pages/Setup/Setup.tsx @@ -2,6 +2,8 @@ import React, { useState } from 'react'; import { useAuth } from '../../contexts/AuthContext'; +const API_BASE_URL = '/api'; + const Setup: React.FC = () => { const [step, setStep] = useState(1); const [formData, setFormData] = useState({ @@ -73,7 +75,7 @@ const Setup: React.FC = () => { console.log('🚀 Sending setup request...', payload); - const response = await fetch('http://localhost:3002/api/setup/admin', { + const response = await fetch(`${API_BASE_URL}/setup/admin`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/frontend/src/services/shiftAssignmentService.ts b/frontend/src/services/shiftAssignmentService.ts index e61ab5b..119ba69 100644 --- a/frontend/src/services/shiftAssignmentService.ts +++ b/frontend/src/services/shiftAssignmentService.ts @@ -6,8 +6,6 @@ import { AssignmentResult, ScheduleRequest } from '../models/scheduling'; const API_BASE_URL = '/api'; - - // Helper function to get auth headers const getAuthHeaders = () => { const token = localStorage.getItem('token'); diff --git a/frontend/src/services/shiftPlanService.ts b/frontend/src/services/shiftPlanService.ts index 9b7958b..64ac1c4 100644 --- a/frontend/src/services/shiftPlanService.ts +++ b/frontend/src/services/shiftPlanService.ts @@ -3,7 +3,7 @@ import { authService } from './authService'; import { ShiftPlan, CreateShiftPlanRequest, ScheduledShift, CreateShiftFromTemplateRequest } from '../models/ShiftPlan'; import { TEMPLATE_PRESETS } from '../models/defaults/shiftPlanDefaults'; -const API_BASE = 'http://localhost:3002/api/shift-plans'; +const API_BASE_URL = '/api/shift-plans'; // Helper function to get auth headers const getAuthHeaders = () => { @@ -25,7 +25,7 @@ const handleResponse = async (response: Response) => { export const shiftPlanService = { async getShiftPlans(): Promise { - const response = await fetch(API_BASE, { + const response = await fetch(API_BASE_URL, { headers: { 'Content-Type': 'application/json', ...authService.getAuthHeaders() @@ -50,7 +50,7 @@ export const shiftPlanService = { }, async getShiftPlan(id: string): Promise { - const response = await fetch(`${API_BASE}/${id}`, { + const response = await fetch(`${API_BASE_URL}/${id}`, { headers: { 'Content-Type': 'application/json', ...authService.getAuthHeaders() @@ -69,7 +69,7 @@ export const shiftPlanService = { }, async createShiftPlan(plan: CreateShiftPlanRequest): Promise { - const response = await fetch(API_BASE, { + const response = await fetch(API_BASE_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -90,7 +90,7 @@ export const shiftPlanService = { }, async updateShiftPlan(id: string, plan: Partial): Promise { - const response = await fetch(`${API_BASE}/${id}`, { + const response = await fetch(`${API_BASE_URL}/${id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', @@ -111,7 +111,7 @@ export const shiftPlanService = { }, async deleteShiftPlan(id: string): Promise { - const response = await fetch(`${API_BASE}/${id}`, { + const response = await fetch(`${API_BASE_URL}/${id}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', @@ -130,7 +130,7 @@ export const shiftPlanService = { // Get specific template or plan getTemplate: async (id: string): Promise => { - const response = await fetch(`${API_BASE}/${id}`, { + const response = await fetch(`${API_BASE_URL}/${id}`, { headers: getAuthHeaders() }); return handleResponse(response); @@ -142,7 +142,7 @@ export const shiftPlanService = { console.log('🔄 Attempting to regenerate scheduled shifts...'); // You'll need to add this API endpoint to your backend - const response = await fetch(`${API_BASE}/${planId}/regenerate-shifts`, { + const response = await fetch(`${API_BASE_URL}/${planId}/regenerate-shifts`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -162,7 +162,7 @@ export const shiftPlanService = { // Create new plan createPlan: async (data: CreateShiftPlanRequest): Promise => { - const response = await fetch(`${API_BASE}`, { + const response = await fetch(`${API_BASE_URL}`, { method: 'POST', headers: getAuthHeaders(), body: JSON.stringify(data), @@ -177,7 +177,7 @@ export const shiftPlanService = { endDate: string; isTemplate?: boolean; }): Promise => { - const response = await fetch(`${API_BASE}/from-preset`, { + const response = await fetch(`${API_BASE_URL}/from-preset`, { method: 'POST', headers: getAuthHeaders(), body: JSON.stringify(data), @@ -204,7 +204,7 @@ export const shiftPlanService = { try { console.log('🔄 Clearing assignments for plan:', planId); - const response = await fetch(`${API_BASE}/${planId}/clear-assignments`, { + const response = await fetch(`${API_BASE_URL}/${planId}/clear-assignments`, { method: 'POST', headers: { 'Content-Type': 'application/json',