Files
bot-dashboard/frontend/lib/api/client.ts
Claude 82b56cf209 fix: Resolve Docker build failures for frontend and backend
Backend fixes:
- Updated psutil from 5.9.8 to 6.1.0 for better ARM64 support and pre-built wheels

Frontend fixes:
- Created missing lib/api/client.ts with axios API client
- Created missing lib/hooks/useStats.ts with system statistics hooks
- Created missing lib/hooks/useBots.ts with bot management hooks
- Fixed .gitignore to not ignore frontend/lib/ directory

These changes resolve the build errors:
- Backend: psutil compilation failure on aarch64
- Frontend: Missing module @/lib/hooks/useStats
2025-11-21 12:05:24 +00:00

49 lines
1.1 KiB
TypeScript

/**
* API client for making requests to the backend.
*/
import axios from "axios";
import type { ApiResponse } from "@/types/api";
const API_BASE_URL =
process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000";
export const apiClient = axios.create({
baseURL: API_BASE_URL,
headers: {
"Content-Type": "application/json",
},
timeout: 10000,
});
// Request interceptor for adding auth token
apiClient.interceptors.request.use(
(config) => {
const token = localStorage.getItem("access_token");
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
// Response interceptor for handling errors
apiClient.interceptors.response.use(
(response) => response,
async (error) => {
if (error.response?.status === 401) {
// Handle token refresh or redirect to login
localStorage.removeItem("access_token");
localStorage.removeItem("refresh_token");
// Optionally redirect to login page
// window.location.href = '/login';
}
return Promise.reject(error);
}
);
export default apiClient;