From 630ad3a94f00e51447bdd992ddcf8e59cc78c0b8 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Wed, 1 Mar 2023 23:34:29 -0300 Subject: [PATCH] Fix landing, api urls --- frontend/src/layout/AppTopbar.vue | 4 +++- frontend/src/views/Chart.vue | 7 +++++-- frontend/src/views/Landing.vue | 6 ------ frontend/src/views/Login.vue | 4 +++- frontend/src/views/OsCrud.vue | 22 +++++++++++----------- frontend/src/views/UserCrud.vue | 12 +++++++----- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/frontend/src/layout/AppTopbar.vue b/frontend/src/layout/AppTopbar.vue index 154c613..caf7738 100644 --- a/frontend/src/layout/AppTopbar.vue +++ b/frontend/src/layout/AppTopbar.vue @@ -7,6 +7,8 @@ import axios from 'axios'; import jwt_decode from 'jwt-decode'; import auth from '../utils/Auth'; +const url = new URL(window.location.href); +const api = (url.port == "5173") ? "http://localhost:3001" : "/api"; const { onMenuToggle } = useLayout(); const outsideClickListener = ref(null); const topbarMenuActive = ref(false); @@ -69,7 +71,7 @@ async function savePassword(pass) { var token = localStorage.getItem("token"); var decoded = jwt_decode(token); try { - const response = await axios.patch(`http://localhost:3001/user/` + decoded.id, pass, auth.getTokenHeader()); + const response = await axios.patch(api + `/user/` + decoded.id, pass, auth.getTokenHeader()); if (response.status !== 204) { console.error(response); } diff --git a/frontend/src/views/Chart.vue b/frontend/src/views/Chart.vue index 90bb26a..6e0212c 100644 --- a/frontend/src/views/Chart.vue +++ b/frontend/src/views/Chart.vue @@ -24,10 +24,13 @@ const setColorOptions = () => { textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary'); surfaceBorder = documentStyle.getPropertyValue('--surface-border'); }; +const url = new URL(window.location.href); +const api = (url.port == "5173") ? "http://localhost:3001" : "/api"; + async function getGames() { try { - const response = await axios.get(`http://localhost:3001/game?limit=5000`); + const response = await axios.get(api + `/game?limit=5000`); games.value = response.data.map(game_id => { return game_id.ID; }); @@ -42,7 +45,7 @@ async function getFrames() { if (selectedGame.value === undefined) { return; } - const response = await axios.get(`http://localhost:3001/frame?limit=5000&game_id=` + selectedGame.value); + const response = await axios.get(api + `/frame?limit=5000&game_id=` + selectedGame.value); if (response.data[response.data.length - 1].elapsed_time >= 10000) { ms.value = false; } diff --git a/frontend/src/views/Landing.vue b/frontend/src/views/Landing.vue index bd8114b..b9611d4 100644 --- a/frontend/src/views/Landing.vue +++ b/frontend/src/views/Landing.vue @@ -41,12 +41,6 @@ const onClickLinux = () => { Features -
  • - - More info - -
  • diff --git a/frontend/src/views/Login.vue b/frontend/src/views/Login.vue index db14aae..edc5caf 100644 --- a/frontend/src/views/Login.vue +++ b/frontend/src/views/Login.vue @@ -7,6 +7,8 @@ const username = ref(''); const password = ref(''); const router = useRouter(); const toast = useToast(); +const url = new URL(window.location.href); +const api = (url.port == "5173") ? "http://localhost:3001" : "/api"; async function onLoginClick() { var login = @@ -15,7 +17,7 @@ async function onLoginClick() { password: password.value }; try { - const response = await axios.post(`http://localhost:3001/login`, login); + const response = await axios.post(api + `/login`, login); if (response.status === 200) { localStorage.setItem('token', response.data.token); router.push('/home'); diff --git a/frontend/src/views/OsCrud.vue b/frontend/src/views/OsCrud.vue index 3184d82..31b13c7 100644 --- a/frontend/src/views/OsCrud.vue +++ b/frontend/src/views/OsCrud.vue @@ -19,10 +19,12 @@ const submitted = ref(false); const checkAuth = () => { auth.checkToken(true); }; +const url = new URL(window.location.href); +const api = (url.port == "5173") ? "http://localhost:3001" : "/api"; async function showTable() { try { - const response = await axios.get(`http://localhost:3001/os`); + const response = await axios.get(api + `/os`); console.log(response.data); users.value = response.data; } @@ -41,7 +43,7 @@ async function onCreateClick() { name: os.value.name }; try { - const response = await axios.post(`http://localhost:3001/os`, newOS, auth.getTokenHeader()); + const response = await axios.post(api + `/os`, newOS, auth.getTokenHeader()); if (response.status === 204) { toast.add({ severity: 'success', summary: 'Successful', detail: 'OS Created', life: 3000 }); @@ -94,7 +96,7 @@ async function onChangeOS() { }; console.log(os.value.ID); try { - const response = await axios.patch(`http://localhost:3001/os/` + os.value.ID, changeOS, auth.getTokenHeader()); + const response = await axios.patch(api + `/os/` + os.value.ID, changeOS, auth.getTokenHeader()); if (response.status === 204) { toast.add({ severity: 'success', summary: 'Successful', detail: 'OS Modified', life: 3000 }); @@ -117,7 +119,7 @@ const confirmDeleteUser = (editUser) => { async function deleteUser() { try { - const response = await axios.delete(`http://localhost:3001/os/` + os.value.ID, auth.getTokenHeader()); + const response = await axios.delete(api + `/os/` + os.value.ID, auth.getTokenHeader()); if (response.status !== 204) { console.error(response); } @@ -139,7 +141,7 @@ const confirmDeleteSelected = () => { const deleteSelectedUsers = () => { selectedUsers.value.forEach(element => { try { - const response = axios.delete(`http://localhost:3001/os/` + element.ID, auth.getTokenHeader()); + const response = axios.delete(api + `/os/` + element.ID, auth.getTokenHeader()); if (response.status !== 204) { console.error(response); } @@ -173,8 +175,8 @@ const initFilters = () => { @@ -185,8 +187,7 @@ const initFilters = () => { :rows="10" :filters="filters" paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown" :rowsPerPageOptions="[5, 10, 25]" - currentPageReportTemplate="Showing {first} to {last} of {totalRecords} users" - responsiveLayout="scroll"> + currentPageReportTemplate="Showing {first} to {last} of {totalRecords} users" responsiveLayout="scroll">