Edit API_URL to dynamic var for deploy

main
Samuel Zielke 7 months ago
parent 3b99c55fe8
commit f5b39ccf4e

@ -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 }),

Loading…
Cancel
Save

Powered by TurnKey Linux.