From af0bc0a082436f55c3bbbd8383a13a8f9102b925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Sun, 10 Jul 2022 15:27:30 -0300 Subject: [PATCH] move api url to .env --- client/.env | 1 + client/src/utils/apiFetch.ts | 3 ++- client/src/utils/swrFetcher.ts | 5 ++--- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 client/.env diff --git a/client/.env b/client/.env new file mode 100644 index 0000000..babc50e --- /dev/null +++ b/client/.env @@ -0,0 +1 @@ +REACT_APP_API_URL=http://localhost:5000 \ No newline at end of file diff --git a/client/src/utils/apiFetch.ts b/client/src/utils/apiFetch.ts index 24fa205..8a1f6c1 100644 --- a/client/src/utils/apiFetch.ts +++ b/client/src/utils/apiFetch.ts @@ -14,5 +14,6 @@ export const createApiClient = ...rest, }; - return fetch(host + input, customInt); + const host = process.env.REACT_APP_API_URL ?? "" + return fetch(`${host}/${input}`, customInt); }; diff --git a/client/src/utils/swrFetcher.ts b/client/src/utils/swrFetcher.ts index 5601f2c..17bc122 100644 --- a/client/src/utils/swrFetcher.ts +++ b/client/src/utils/swrFetcher.ts @@ -1,5 +1,3 @@ -const host = "http://localhost:5000/"; - export const createSWRFetcher = (token: string | null) => async (input: RequestInfo | URL, init?: RequestInit) => { const { headers, ...rest } = init ?? {}; @@ -13,6 +11,7 @@ export const createSWRFetcher = ...rest, }; - const res = await fetch(host + input, customInt); + const host = process.env.REACT_APP_API_URL ?? "" + const res = await fetch(`${host}/${input}`, customInt); return await res.json(); };