diff --git a/client/.env b/client/.env index a11a7cc..27cbd14 100644 --- a/client/.env +++ b/client/.env @@ -1,3 +1,3 @@ VITE_TEST_VAR=123 -# VITE_SERVER_API=http://192.168.56.1:3000/ +# VITE_SERVER_API=http://192.168.1.158:3002 VITE_SERVER_API=https://irth.graff.tech/api \ No newline at end of file diff --git a/client/package.json b/client/package.json index fd5fc7c..c87c830 100644 --- a/client/package.json +++ b/client/package.json @@ -31,6 +31,7 @@ "zustand": "^4.5.2" }, "devDependencies": { + "@types/node": "^20.14.8", "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@types/react-transition-group": "^4.4.10", diff --git a/client/src/components/searchPage/LayoutOptions.tsx b/client/src/components/searchPage/LayoutOptions.tsx index 0d2a4e1..884f78a 100644 --- a/client/src/components/searchPage/LayoutOptions.tsx +++ b/client/src/components/searchPage/LayoutOptions.tsx @@ -67,8 +67,8 @@ const LayoutOptions = () => { const zohoToken = localStorage.getItem("ACCESS_TOKEN"); setIsLoading(true); - updateAccessToken() - .then((token) => { + if (!zohoToken) { + updateAccessToken().then((token) => { if (token) { getFilteredApartments( token, @@ -81,64 +81,52 @@ const LayoutOptions = () => { sortList, pageInitial, perPage - ); + ).then(() => { + setIsLoading(false); + }); } - }) - .then(() => - getFilteredApartments( - zohoToken, - setApartments, - roveHomeTypeCheckboxes, - apartmentTypeCheckboxes, - debouncedSliders, - switchers, - viewCheckboxes, - sortList, - pageInitial, - perPage - ) - ) - .finally(() => { - setIsLoading(false); }); + } else { + getFilteredApartments( + zohoToken, + setApartments, + roveHomeTypeCheckboxes, + apartmentTypeCheckboxes, + debouncedSliders, + switchers, + viewCheckboxes, + sortList, + pageInitial, + perPage + ) + .catch((error) => { + const errorStatus = error.response.status; - // getFilteredApartments( - // zohoToken, - // setApartments, - // roveHomeTypeCheckboxes, - // apartmentTypeCheckboxes, - // debouncedSliders, - // switchers, - // viewCheckboxes, - // sortList, - // pageInitial, - // perPage - // ) - // .catch((error) => { - // const errorStatus = error.response.status; - - // if (errorStatus === 401) { - // updateAccessToken().then((token) => { - // if (token) { - // getFilteredApartments( - // token, - // setApartments, - // roveHomeTypeCheckboxes, - // apartmentTypeCheckboxes, - // debouncedSliders, - // switchers, - // viewCheckboxes, - // sortList, - // pageInitial, - // perPage - // ); - // } - // }); - // } - // }) - // .finally(() => { - // setIsLoading(false); - // }); + if (errorStatus === 401) { + updateAccessToken().then((token) => { + if (token) { + getFilteredApartments( + token, + setApartments, + roveHomeTypeCheckboxes, + apartmentTypeCheckboxes, + debouncedSliders, + switchers, + viewCheckboxes, + sortList, + pageInitial, + perPage + ).then(() => { + setIsLoading(false); + }); + } + }); + } + }) + .then(() => { + setIsLoading(false); + }); + } }, [ setApartments, roveHomeTypeCheckboxes, diff --git a/client/vite.config.ts b/client/vite.config.ts index 5a33944..9f3ead8 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -1,7 +1,20 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' +import { defineConfig, loadEnv } from "vite"; +import react from "@vitejs/plugin-react"; // https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], -}) +export default defineConfig(({ mode }) => { + process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }; + + return { + plugins: [react()], + server: { + proxy: { + "/api": { + target: process.env.VITE_SERVER_API, + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, ""), + }, + }, + }, + }; +}); diff --git a/client/yarn.lock b/client/yarn.lock index a57bc2e..87a859e 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -709,6 +709,13 @@ resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz" integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== +"@types/node@^20.14.8": + version "20.14.8" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.8.tgz#45c26a2a5de26c3534a9504530ddb3b27ce031ac" + integrity sha512-DO+2/jZinXfROG7j7WKFn/3C6nFwxy2lLpgLjEXJz+0XKphZlTLJ14mo8Vfg8X5BWN6XjyESXq+LcYdT7tR3bA== + dependencies: + undici-types "~5.26.4" + "@types/offscreencanvas@^2019.6.4": version "2019.7.3" resolved "https://registry.yarnpkg.com/@types/offscreencanvas/-/offscreencanvas-2019.7.3.tgz#90267db13f64d6e9ccb5ae3eac92786a7c77a516" @@ -2622,6 +2629,11 @@ ua-parser-js@^1.0.33: resolved "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.37.tgz" integrity sha512-bhTyI94tZofjo+Dn8SN6Zv8nBDvyXTymAdM3LDI/0IboIUwTu1rEhW7v2TfiVsoYWgkQ4kOVqnI8APUFbIQIFQ== +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + update-browserslist-db@^1.0.13: version "1.0.13" resolved "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz" diff --git a/server/.env b/server/.env index 3f3f579..238f74e 100644 --- a/server/.env +++ b/server/.env @@ -1,2 +1,2 @@ -PORT=3000 +PORT=3002 REFRESH_TOKEN=1000.da3146d49fa8a399f0c635e74954ff9c.e010dbb1bb605d7e1aa5bf7fc0521f8b \ No newline at end of file diff --git a/server/ecosystem.config.cjs b/server/ecosystem.config.cjs new file mode 100644 index 0000000..6f6a2f2 --- /dev/null +++ b/server/ecosystem.config.cjs @@ -0,0 +1,8 @@ +module.exports = { + apps: [ + { + name: "irth-server:3002", + script: "./dist", + }, + ], +};