🔧 chore(frontend): update build script in package.json to set NODE_ENV=development for build command

🔧 chore(frontend): add BASE_URL_API constant to constants.ts to store API base URL
🔧 chore(frontend): update API endpoints in controllers to use BASE_URL_API constant for better maintainability and flexibility
This commit is contained in:
Cristhian Zanforlin Lousa 2023-08-12 00:26:57 -03:00
commit b5987318f6
3 changed files with 12 additions and 8 deletions

View file

@ -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}\""
},

View file

@ -608,3 +608,5 @@ export function tabsArray(codes: string[], method: number) {
},
];
}
export const BASE_URL_API = "http://localhost:7860/";

View file

@ -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<Users> {
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<Users> {
export async function addUser(user: UserInputType): Promise<Users> {
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;
}