From 85403602173356a16a8bf40ef5356c5176c87507 Mon Sep 17 00:00:00 2001 From: Ben Elferink Date: Wed, 27 Oct 2021 19:26:02 +0300 Subject: [PATCH] tweak: utils and constants - frontend --- client/.env.example | 1 + client/src/api/index.js | 9 --------- client/src/constants/index.js | 8 ++++++++ client/src/contexts/AuthContext.js | 2 +- client/src/utils/axios.js | 7 +++++++ 5 files changed, 17 insertions(+), 10 deletions(-) delete mode 100644 client/src/api/index.js create mode 100644 client/src/constants/index.js create mode 100644 client/src/utils/axios.js diff --git a/client/.env.example b/client/.env.example index e69de29..705be85 100644 --- a/client/.env.example +++ b/client/.env.example @@ -0,0 +1 @@ +REACT_APP_BACKEND_URL = "" \ No newline at end of file diff --git a/client/src/api/index.js b/client/src/api/index.js deleted file mode 100644 index 9566bc6..0000000 --- a/client/src/api/index.js +++ /dev/null @@ -1,9 +0,0 @@ -import axios from 'axios' - -// api url (where your serve is hosted at) -export const backendUrl = 'http://localhost:8080' - -// axios configuration -export default axios.create({ - baseURL: backendUrl, -}) diff --git a/client/src/constants/index.js b/client/src/constants/index.js new file mode 100644 index 0000000..d02b66a --- /dev/null +++ b/client/src/constants/index.js @@ -0,0 +1,8 @@ +const { + // api url (where your server is hosted at) + REACT_APP_BACKEND_URL: BACKEND_URL = 'http://localhost:8080', +} = process.env + +export { + BACKEND_URL, +} diff --git a/client/src/contexts/AuthContext.js b/client/src/contexts/AuthContext.js index ba48721..3ab0e82 100644 --- a/client/src/contexts/AuthContext.js +++ b/client/src/contexts/AuthContext.js @@ -1,5 +1,5 @@ import { createContext, useContext, useState, useEffect } from 'react' -import axios from '../api' +import axios from '../utils/axios' // init context const AuthContext = createContext() diff --git a/client/src/utils/axios.js b/client/src/utils/axios.js new file mode 100644 index 0000000..f59bd15 --- /dev/null +++ b/client/src/utils/axios.js @@ -0,0 +1,7 @@ +import axios from 'axios' +import { BACKEND_URL } from '../constants' + +// axios configuration +export default axios.create({ + baseURL: BACKEND_URL, +})