#57 makeRequest uses env variable so all requests use the configuration

This commit is contained in:
2023-04-14 12:55:43 -04:00
parent 1f0e8ca905
commit c1a8f04dc7
7 changed files with 31 additions and 11 deletions

View File

@@ -1,4 +1,6 @@
const makeRequest = ({ url, method, body = null }): Promise<Response> => {
const { REACT_APP_BACKEND_URL } = process.env;
const makeRequest = ({ endpoint, method, body = null }): Promise<Response> => {
const req: RequestInit = {
method: method,
credentials: "include",
@@ -8,7 +10,7 @@ const makeRequest = ({ url, method, body = null }): Promise<Response> => {
if (body) {
req["body"] = JSON.stringify(body);
}
return fetch(url, req);
return fetch(`${REACT_APP_BACKEND_URL}/${endpoint}`, req);
};
const sendLoginRequest = async (
@@ -17,7 +19,7 @@ const sendLoginRequest = async (
): Promise<object> => {
const p: Promise<object> = new Promise(async (res) => {
await makeRequest({
url: "http://localhost:5000/login",
endpoint: "login",
method: "POST",
body: { username, password },
})
@@ -36,7 +38,7 @@ const sendLoginRequest = async (
const sendLogoutRequest = async (): Promise<object> => {
const p: Promise<object> = new Promise(async (res) => {
await makeRequest({
url: "http://localhost:5000/logout",
endpoint: "logout",
method: "POST",
})
.then((resp) => resp.json())