From f5b39ccf4e0aa990732f0404531dce5e8969db68 Mon Sep 17 00:00:00 2001 From: Samuel Zielke Date: Wed, 14 May 2025 18:06:36 +0200 Subject: [PATCH] Edit API_URL to dynamic var for deploy --- frontend/src/App.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index 4c2e22a..4058006 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,6 +1,7 @@ import React, { useEffect, useState, useRef } from "react"; function App() { + const API_BASE = process.env.REACT_APP_API_URL || "myday.samuelzielke.de"; const [datum, setDatum] = useState("2025-05-14"); const [data, setData] = useState({ abwesenheiten: [], zeitslots: [] }); const [startzeit, setStartzeit] = useState(null); @@ -48,8 +49,8 @@ function App() { const handleSaveEdit = async (typ) => { const url = typ === "abwesenheit" - ? `http://localhost:3001/api/abwesenheit/${editAbwesenheitId}` - : `http://localhost:3001/api/zeitslot/${editZeitslotId}`; + ? `${API_BASE}/api/abwesenheit/${editAbwesenheitId}` + : `${API_BASE}/api/zeitslot/${editZeitslotId}`; await fetch(url, { method: "PUT", headers: { "Content-Type": "application/json" }, @@ -63,7 +64,7 @@ function App() { const handleSaveNew = async () => { const endpoint = isAbwesenheit ? "abwesenheit" : "zeitslot"; - await fetch(`http://localhost:3001/api/${endpoint}`, { + await fetch(`${API_BASE}/api/${endpoint}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ datum, ...newEntry }), @@ -74,7 +75,7 @@ function App() { }; const deleteEntry = async (id, typ) => { - const url = `http://localhost:3001/api/${typ}/${id}`; + const url = `${API_BASE}/api/${typ}/${id}`; await fetch(url, { method: "DELETE" }); reloadData(); if (typ === "abwesenheit") setEditAbwesenheitId(null); @@ -83,7 +84,7 @@ function App() { // Daten laden useEffect(() => { - fetch(`http://localhost:3001/api/data/${datum}`) + fetch(`${API_BASE}/api/data/${datum}`) .then((res) => res.json()) .then((data) => { setData(data); @@ -94,7 +95,7 @@ function App() { const reloadData = () => { - fetch(`http://localhost:3001/api/data/${datum}`) + fetch(`${API_BASE}/api/data/${datum}`) .then((res) => res.json()) .then((data) => { setData(data); @@ -111,7 +112,7 @@ function App() { }; const saveManualEndzeit = async () => { - await fetch("http://localhost:3001/api/endzeit", { + await fetch(`${API_BASE}/api/endzeit`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ datum, zeit: manualEndzeit }), @@ -129,7 +130,7 @@ function App() { }; const saveManualStartzeit = async () => { - await fetch("http://localhost:3001/api/startzeit", { + await fetch(`${API_BASE}/api/startzeit`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ datum, zeit: manualStartzeit }),