#57 makeRequest uses env variable so all requests use the configuration
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user