move api url to .env

This commit is contained in:
João Geonizeli
2022-07-10 15:27:30 -03:00
parent acaba0f9ca
commit af0bc0a082
3 changed files with 5 additions and 4 deletions

1
client/.env Normal file
View File

@@ -0,0 +1 @@
REACT_APP_API_URL=http://localhost:5000

View File

@@ -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);
};

View File

@@ -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();
};