From cb23997dcad994582118b2a474f1d24c0a3d74f7 Mon Sep 17 00:00:00 2001 From: Massimiliano De Luise <66636702+MDeLuise@users.noreply.github.com> Date: Sun, 10 Sep 2023 15:56:57 +0200 Subject: [PATCH] feature: add customization of timeout for backend's responses (#26) --- README.md | 1 + deployment/frontend.env | 1 + frontend/.env | 1 + frontend/src/App.tsx | 3 ++- frontend/src/index.tsx | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7ce5e57..dfb47c21 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,7 @@ There are 2 configuration file available: ``` PORT=3000 # port that will serve the frontend, if on docker deployment leave as it is and change the port binding in the docker-compose file if needed API_URL=http://localhost:8080/api + WAIT_TIMEOUT=5000 # timeout for backend responses (in milliseconds) PAGE_SIZE=25 diff --git a/deployment/frontend.env b/deployment/frontend.env index 20928e5a..7958586b 100644 --- a/deployment/frontend.env +++ b/deployment/frontend.env @@ -1,5 +1,6 @@ PORT=3000 API_URL=http://localhost:8080/api +WAIT_TIMEOUT=5000 PAGE_SIZE=25 diff --git a/frontend/.env b/frontend/.env index b3784e33..b68e9eb8 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1,4 +1,5 @@ PORT=3000 API_URL=http://localhost:8085/api +WAIT_TIMEOUT=5000 PAGE_SIZE=25 diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f2478591..2971b49a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -15,9 +15,10 @@ const ColorModeContext = React.createContext({ toggleColorMode: () => { } }); export function App() { const isLoggedIn: () => boolean = () => secureLocalStorage.getItem("plant-it-key") != null; const backendURL = window._env_.API_URL != null ? window._env_.API_URL : "http://localhost:8085/api"; + const axiosTimeout = window._env_.WAIT_TIMEOUT != null ? window._env_.WAIT_TIMEOUT : 5000; const axiosReq = axios.create({ baseURL: backendURL, - timeout: 5000 + timeout: axiosTimeout, }); axiosReq.interceptors.request.use( diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index d76afb1b..153180cc 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -10,6 +10,7 @@ declare global { interface Window { _env_: { API_URL: string + WAIT_TIMEOUT: number | undefined } } }