feat: Refactor API URL handling and add base path support (#131)

This commit is contained in:
samanhappy
2025-05-27 16:11:35 +08:00
committed by GitHub
parent 37bb3414c8
commit 268ce5cce6
18 changed files with 624 additions and 443 deletions

View File

@@ -2,6 +2,7 @@ import { useState, useCallback, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { ApiResponse } from '@/types';
import { useToast } from '@/contexts/ToastContext';
import { getApiUrl } from '../utils/api';
// Define types for the settings data
interface RoutingConfig {
@@ -80,7 +81,7 @@ export const useSettingsData = () => {
try {
const token = localStorage.getItem('mcphub_token');
const response = await fetch('/api/settings', {
const response = await fetch(getApiUrl('/settings'), {
headers: {
'x-auth-token': token || '',
},
@@ -136,7 +137,7 @@ export const useSettingsData = () => {
try {
const token = localStorage.getItem('mcphub_token');
const response = await fetch('/api/system-config', {
const response = await fetch(getApiUrl('/system-config'), {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
@@ -183,7 +184,7 @@ export const useSettingsData = () => {
try {
const token = localStorage.getItem('mcphub_token');
const response = await fetch('/api/system-config', {
const response = await fetch(getApiUrl('/system-config'), {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
@@ -233,7 +234,7 @@ export const useSettingsData = () => {
try {
const token = localStorage.getItem('mcphub_token');
const response = await fetch('/api/system-config', {
const response = await fetch(getApiUrl('/system-config'), {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
@@ -283,7 +284,7 @@ export const useSettingsData = () => {
try {
const token = localStorage.getItem('mcphub_token');
const response = await fetch('/api/system-config', {
const response = await fetch(getApiUrl('/system-config'), {
method: 'PUT',
headers: {
'Content-Type': 'application/json',