chore: fix url api
This commit is contained in:
@@ -9,8 +9,8 @@ import type {
|
|||||||
Alert,
|
Alert,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
const V2 = "http://172.20.167.237:8080/api/v2";
|
const V2 = "https://uber-stup.club/api/v2";
|
||||||
const CABINE_URL = "http://172.20.167.237:8080/api/v1/cabine";
|
const CABINE_URL = "https://uber-stup.club/api/v1/cabine";
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// AUTH
|
// AUTH
|
||||||
@@ -378,7 +378,7 @@ export const createClientByAdmin = async (data: {
|
|||||||
telephone: string;
|
telephone: string;
|
||||||
}) => {
|
}) => {
|
||||||
const { data: res } = await apiClient.post(
|
const { data: res } = await apiClient.post(
|
||||||
`http://172.20.167.237:8080/api/v1/auth/register`,
|
`https://uber-stup.club/api/v1/auth/register`,
|
||||||
data,
|
data,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import type {
|
|||||||
Alert,
|
Alert,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
const API = "http://172.20.167.237:8080/api/v1/cabine";
|
const API = "https://uber-stup.club/api/v1/cabine";
|
||||||
const V2 = "http://172.20.167.237:8080/api/v2";
|
const V2 = "https://uber-stup.club/api/v2";
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// ITEMS
|
// ITEMS
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type {
|
|||||||
Alert,
|
Alert,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
const API = "http://172.20.167.237:8080/api/v1/livreur";
|
const API = "https://uber-stup.club/api/v1/livreur";
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// STATUT
|
// STATUT
|
||||||
|
|||||||
@@ -1,43 +1,42 @@
|
|||||||
import axios from 'axios';
|
import axios from "axios";
|
||||||
import { getToken, getAdminToken } from '../auth/tokenStorage';
|
import { getToken, getAdminToken } from "../auth/tokenStorage";
|
||||||
|
|
||||||
// Change this to your server IP/domain
|
// Change this to your server IP/domain
|
||||||
export const API_BASE_URL = 'http://localhost:8080';
|
export const API_BASE_URL = "https://uber-stup.club";
|
||||||
|
|
||||||
const apiClient = axios.create({
|
const apiClient = axios.create({
|
||||||
baseURL: API_BASE_URL,
|
baseURL: API_BASE_URL,
|
||||||
timeout: 15000,
|
timeout: 15000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Request interceptor: attach JWT token
|
// Request interceptor: attach JWT token
|
||||||
apiClient.interceptors.request.use(async (config) => {
|
apiClient.interceptors.request.use(async (config) => {
|
||||||
// Determine which token to use based on URL
|
// Determine which token to use based on URL
|
||||||
const isAdminRoute = config.url?.includes('/api/v2/') ||
|
const isAdminRoute =
|
||||||
config.url?.includes('/api/v1/cabine/') ||
|
config.url?.includes("/api/v2/") ||
|
||||||
config.url?.includes('/api/v1/livreur/');
|
config.url?.includes("/api/v1/cabine/") ||
|
||||||
|
config.url?.includes("/api/v1/livreur/");
|
||||||
|
|
||||||
const token = isAdminRoute
|
const token = isAdminRoute ? await getAdminToken() : await getToken();
|
||||||
? await getAdminToken()
|
|
||||||
: await getToken();
|
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
config.headers.Authorization = `Bearer ${token}`;
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Response interceptor: handle common errors
|
// Response interceptor: handle common errors
|
||||||
apiClient.interceptors.response.use(
|
apiClient.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(error) => {
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
console.log('Session expirée');
|
console.log("Session expirée");
|
||||||
}
|
}
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export default apiClient;
|
export default apiClient;
|
||||||
|
|||||||
Reference in New Issue
Block a user