Skip to content

Commit

Permalink
Add base options for fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
robvk committed Aug 30, 2022
1 parent 1eb0ef4 commit 08e3181
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion client/src/hooks/useFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ const useFetch = (route, onReceived) => {
setError(null);
setIsLoading(true);

const baseOptions = {
method: "GET",
headers: {
"content-type": "application/json",
},
};

const fetchData = async () => {
// We add the /api subsection here to make it a single point of change if our configuration changes
const url = `${process.env.BASE_SERVER_URL}/api${route}`;

const res = await fetch(url, { ...options, signal });
const res = await fetch(url, { ...baseOptions, ...options, signal });

if (!res.ok) {
setError(
Expand Down

0 comments on commit 08e3181

Please sign in to comment.