added .env link function

This commit is contained in:
2025-10-04 00:26:02 +02:00
parent 5131266242
commit 6ea1ff799c
11 changed files with 85 additions and 30 deletions

View File

@@ -1,9 +1,14 @@
import Cookies from "js-cookie";
const API_BASE =
(import.meta as any).env?.VITE_BACKEND_URL ||
import.meta.env.VITE_BACKEND_URL ||
"http://localhost:8002";
export const handleDelete = async (userId: number) => {
try {
const response = await fetch(
`http://localhost:8002/api/deleteUser/${userId}`,
`${API_BASE}/api/deleteUser/${userId}`,
{
method: "DELETE",
headers: {
@@ -28,7 +33,7 @@ export const handleEdit = async (
) => {
try {
const response = await fetch(
`http://localhost:8002/api/editUser/${userId}`,
`${API_BASE}/api/editUser/${userId}`,
{
method: "POST",
headers: {
@@ -54,7 +59,7 @@ export const createUser = async (
password: string
) => {
try {
const response = await fetch(`http://localhost:8002/api/createUser`, {
const response = await fetch(`${API_BASE}/api/createUser`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -74,7 +79,7 @@ export const createUser = async (
export const changePW = async (newPassword: string, username: string) => {
try {
const response = await fetch(`http://localhost:8002/api/changePWadmin`, {
const response = await fetch(`${API_BASE}/api/changePWadmin`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -95,7 +100,7 @@ export const changePW = async (newPassword: string, username: string) => {
export const deleteLoan = async (loanId: number) => {
try {
const response = await fetch(
`http://localhost:8002/api/deleteLoan/${loanId}`,
`${API_BASE}/api/deleteLoan/${loanId}`,
{
method: "DELETE",
headers: {
@@ -116,7 +121,7 @@ export const deleteLoan = async (loanId: number) => {
export const deleteItem = async (itemId: number) => {
try {
const response = await fetch(
`http://localhost:8002/api/deleteItem/${itemId}`,
`${API_BASE}/api/deleteItem/${itemId}`,
{
method: "DELETE",
headers: {
@@ -139,7 +144,7 @@ export const createItem = async (
can_borrow_role: number
) => {
try {
const response = await fetch(`http://localhost:8002/api/createItem`, {
const response = await fetch(`${API_BASE}/api/createItem`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -167,7 +172,7 @@ export const handleEditItems = async (
can_borrow_role: string
) => {
try {
const response = await fetch("http://localhost:8002/api/updateItemByID", {
const response = await fetch(`${API_BASE}/api/updateItemByID`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -188,7 +193,7 @@ export const handleEditItems = async (
export const changeSafeState = async (itemId: number) => {
try {
const response = await fetch(
`http://localhost:8002/api/changeSafeState/${itemId}`,
`${API_BASE}/api/changeSafeState/${itemId}`,
{
method: "PUT",
headers: {
@@ -208,7 +213,7 @@ export const changeSafeState = async (itemId: number) => {
export const createAPIentry = async (apiKey: string, user: string) => {
try {
const response = await fetch(`http://localhost:8002/api/createAPIentry`, {
const response = await fetch(`${API_BASE}/api/createAPIentry`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -233,7 +238,7 @@ export const createAPIentry = async (apiKey: string, user: string) => {
export const deleteAPKey = async (apiKeyId: number) => {
try {
const response = await fetch(
`http://localhost:8002/api/deleteAPKey/${apiKeyId}`,
`${API_BASE}/api/deleteAPKey/${apiKeyId}`,
{
method: "DELETE",
headers: {