From db0c85ee3debd7f01db332a7f55cd1cac13528b3 Mon Sep 17 00:00:00 2001 From: matheusyanmonteiro Date: Wed, 5 Feb 2025 15:20:52 -0300 Subject: [PATCH] feat: create the integration with other services back-end --- .env | 3 +++ .env.example | 2 ++ src/config/environment.ts | 2 ++ src/hooks/useApi/index.tsx | 13 ++++++++----- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..b35b4ba --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +VITE_API_BASE_URL=http://localhost:3000 +VITE_API_BOOKS_URL=http://localhost:3001 +VITE_API_RENTALS_URL=http://localhost:3003 \ No newline at end of file diff --git a/.env.example b/.env.example index 99cbcd5..b35b4ba 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,3 @@ VITE_API_BASE_URL=http://localhost:3000 +VITE_API_BOOKS_URL=http://localhost:3001 +VITE_API_RENTALS_URL=http://localhost:3003 \ No newline at end of file diff --git a/src/config/environment.ts b/src/config/environment.ts index 1b098b1..8e915e2 100644 --- a/src/config/environment.ts +++ b/src/config/environment.ts @@ -1 +1,3 @@ export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL; +export const API_BOOKS_URL = import.meta.env.VITE_API_BOOKS_URL; +export const API_RENTALS_URL = import.meta.env.VITE_API_RENTALS_URL; \ No newline at end of file diff --git a/src/hooks/useApi/index.tsx b/src/hooks/useApi/index.tsx index 55a13d8..93773c6 100644 --- a/src/hooks/useApi/index.tsx +++ b/src/hooks/useApi/index.tsx @@ -1,6 +1,6 @@ import axios from "axios"; import { useMemo } from "react" -import { API_BASE_URL } from "../../config/environment"; +import { API_BASE_URL, API_BOOKS_URL, API_RENTALS_URL } from "../../config/environment"; import { User } from "../../interfaces/user"; const createApiInstance = (url: string) => { @@ -22,8 +22,11 @@ const getDefaultErrorUseAPIMessage = (err: any) => { const useApi = () => { const api = useMemo( - () => - createApiInstance(API_BASE_URL), + () => ({ + base: createApiInstance(API_BASE_URL), + books: createApiInstance(API_BOOKS_URL), + rentals: createApiInstance(API_RENTALS_URL), + }), [], ); @@ -36,7 +39,7 @@ const useApi = () => { refreshToken: string; } }> => { return new Promise((resolve) => { - api + api.base .post('/auth/signin', { ...data, role: 'admin', @@ -53,7 +56,7 @@ const useApi = () => { total: number, } }> => { return new Promise((resolve) => { - api + api.base .get('/users', { params: { perPage: data.perPage,