From b5987318f67f229979474d655652ddf915ab87ef Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Sat, 12 Aug 2023 00:26:57 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(frontend):=20update=20buil?= =?UTF-8?q?d=20script=20in=20package.json=20to=20set=20NODE=5FENV=3Ddevelo?= =?UTF-8?q?pment=20for=20build=20command=20=F0=9F=94=A7=20chore(frontend):?= =?UTF-8?q?=20add=20BASE=5FURL=5FAPI=20constant=20to=20constants.ts=20to?= =?UTF-8?q?=20store=20API=20base=20URL=20=F0=9F=94=A7=20chore(frontend):?= =?UTF-8?q?=20update=20API=20endpoints=20in=20controllers=20to=20use=20BAS?= =?UTF-8?q?E=5FURL=5FAPI=20constant=20for=20better=20maintainability=20and?= =?UTF-8?q?=20flexibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/package.json | 2 +- src/frontend/src/constants/constants.ts | 2 ++ src/frontend/src/controllers/API/index.ts | 16 +++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/frontend/package.json b/src/frontend/package.json index b4afc7999..a7fe6ee4f 100644 --- a/src/frontend/package.json +++ b/src/frontend/package.json @@ -69,7 +69,7 @@ "scripts": { "dev:docker": "vite --host 0.0.0.0", "start": "vite", - "build": "vite build", + "build": "vite build NODE_ENV=development", "serve": "vite preview", "format": "npx prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"" }, diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index 5353453b1..c7e8301db 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -608,3 +608,5 @@ export function tabsArray(codes: string[], method: number) { }, ]; } + +export const BASE_URL_API = "http://localhost:7860/"; \ No newline at end of file diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 5e66b6241..1b4fd30d6 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -17,6 +17,8 @@ import { UploadFileTypeAPI, errorsTypeAPI, } from "./../../types/api/index"; +import { BASE_URL_API } from "../../constants/constants"; + /** * Fetches all objects from the API endpoint. @@ -356,7 +358,7 @@ export async function postCustomComponent( export async function onLogin(user: LoginType) { try { const response = await api.post( - "http://localhost:7860/login", + `${BASE_URL_API}login`, new URLSearchParams({ username: user.username, password: user.password, @@ -379,7 +381,7 @@ export async function onLogin(user: LoginType) { export async function renewAccessToken(token: string) { try { - return await api.post(`http://localhost:7860/refresh?token=${token}`); + return await api.post(`${BASE_URL_API}refresh?token=${token}`); } catch (error) { console.log("Error:", error); throw error; @@ -388,7 +390,7 @@ export async function renewAccessToken(token: string) { export async function getUsers(): Promise { try { - return await api.get(`http://localhost:7860/user`); + return await api.get(`${BASE_URL_API}user`); } catch (error) { console.log("Error:", error); throw error; @@ -397,7 +399,7 @@ export async function getUsers(): Promise { export async function addUser(user: UserInputType): Promise { try { - const res = await api.post(`http://localhost:7860/user`, user); + const res = await api.post(`${BASE_URL_API}user`, user); if (res.status === 200) { return res.data; } @@ -413,7 +415,7 @@ export async function getUsersPage( ): Promise<[Users]> { try { const res = await api.get( - `http://localhost:7860/users?skip=${skip}&limit=${limit}` + `${BASE_URL_API}users?skip=${skip}&limit=${limit}` ); if (res.status === 200) { return res.data; @@ -426,7 +428,7 @@ export async function getUsersPage( export async function deleteUser(user_id: string) { try { - const res = await api.delete(`http://localhost:7860/user/${user_id}`); + const res = await api.delete(`${BASE_URL_API}user/${user_id}`); if (res.status === 200) { return res.data; } @@ -438,7 +440,7 @@ export async function deleteUser(user_id: string) { export async function updateUser(user_id: string, user: Users) { try { - const res = await api.patch(`http://localhost:7860/user/${user_id}`, user); + const res = await api.patch(`${BASE_URL_API}user/${user_id}`, user); if (res.status === 200) { return res.data; }